zoukankan      html  css  js  c++  java
  • Linux防火墙firewall和iptables的使用

    防火墙是整个数据包进入主机前的第一道关卡。
    Linux中有两种防火墙软件,ConterOS 7.0以上使用的是 firewallConterOS 7.0以下使用的是 iptables,本文将分别介绍两种防火墙软件的使用。

    1.验证本机系统使用的是哪个防火墙

    	systemctl status iptables.service       查看 iptables 防火墙的状态
    	systemctl status firewalld.service      查看 firewall 防火墙的状态
    


    2.使用 防火墙——firewalld

    2.1 安装 firewalld

    	yum install firewalld         安装 firewalld 防火墙
    
    	systemctl unmask firewalld    解除屏蔽
    
    	systemctl stop iptables       停止 iptables 防火墙
    

    2.2 基本操作

    	systemctl status firewalld      查看防火墙状态
    
    	systemctl start firewalld       启动防火墙
    
    	systemctl stop firewalld        关闭防火墙
    
    	systemctl restart firewalld     重启防火墙
    
    	systemctl enable firewalld      设置开机自启
    
    	systemctl disable firewalld     禁用开机启动
    

    2.3 对端口的操作

    	firewall-cmd --zone=public --add-port=8080/tcp --permanent      开放8080端口
    
    	firewall-cmd --zone=public --remove-port=8080/tcp --permanent   关闭8080端口
    
    	firewall-cmd --reload     更新配置信息(这样就不需要重启防火墙了)
    

    2.4 查看操作

    	firewall-cmd --list-ports     查看开放的端口
    
    	systemctl list-unit-files | grep enabled    查看所有开机自启的服务
    


    3.使用 防火墙——iptables

    3.1 安装 iptables

    	systemctl stop firewalld       停止 firewalld 防火墙
    
    	systemctl mask firewalld       屏蔽 firewalld 防火墙
    
    	yum -y install iptables        安装 iptables
    
    	yum -y install iptables-services      安装 iptables-services
    

    3.2 基本操作

    	systemctl start iptables.service       启动 iptables 防火墙
    
    	systemctl status iptables.service      查看 iptables 防火墙状态
    
    	systemctl enable iptables.service      设置开机自启
    
    	systemctl disable iptables.service     禁用开机自启
    

    3.3 对端口的操作

    • 3.3.1 放行端口(两种方式)

    方式一:
    	1.编辑 /etc/sysconfig/iptables 文件。执行命令:vim /etc/sysconfig/iptables
    	2.复制 22号端口那一行,并粘贴到下一行,修改22为8080
    	3.写入保存并退出
    	4.systemctl restart iptables     重启iptables服务(这样8080端口就被开放了)
    
    方式二:
    	iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT     开启8080端口    
    	service iptables save         保存配置信息(如果不执行保存,系统重启后8080端口将失效)
    	systemctl restart iptables    重启iptables服务
    
    • 3.3.2 删除端口

    删除对应的规则,就要知道对应的编号
    	iptables -L -n --line-number     显示规则和相对应的编号
    --
    如果 8080 端口规则编号为6
    	iptables -D INPUT 6              删除规则编号为6的端口
    	service iptables save            保存配置信息(如果不执行保存,重启后端口还是会被开放)
    

    3.4 查看操作

    	iptables -L -n     查看 iptables 开放的端口
    


  • 相关阅读:
    Ext.Net多表头跨行跨列
    操作文件
    HighMaps
    HighCharts动态读取显示
    SAP CRM 项目笔记(一) SOW(工作说明书)讨论
    .net 动态编译解决考勤计算问题
    CPU的大小端模式
    将一个数转化为任意进制的数
    关于内存对齐
    常量指针与指针常量
  • 原文地址:https://www.cnblogs.com/orangebooks/p/12045269.html
Copyright © 2011-2022 走看看