第八章 iptables和firewalld防火墙

iptables rhel5、rhel6、rhel7.0、7.1


firewalld ------- firewall-cmd--------命令行 firewall-config------图形化


tcp_wrappers


网卡配置: 编辑/etc/sysconfig/network-script/ifcfg-eno16777736(选择相关网卡)

nmtui网络配置工具(rhel5/6 是setup)

nm-connection-editor



防火墙动作: 允许:ACCEPT 拒绝:REJECT(能看到拒绝信息) 丢弃:DROP(不能看到拒绝信息,显示超时) 日志:LOG




8.1iptables

iptables -L -------------------------------------查看防火墙规则 iptables -F -------------------------------------清空防火墙规则 iptables -D INPUT 1 -------------------------删除input第一条 iptables -P INPUT DROP ------------------丢弃入方向所有流量 iptables -I INPUT -j REJECT -p tcp --dport 22 -------------------拒绝tcp协议的22号端口,插入列表最前 iptables -I INPUT -j ACCEPT -p tcp --dport 22 -s 192.168.1.2 ------------允许源地址为XXX.XXXtcp协议的22端口,插入列表最前 iptables -I INPUT -j ACCEPT -p tcp --dport **1000:2000 **-s 192.168.1.0/24 ------------1000至2000端口;192.168.1.0/24网段




8.2 firewalld firewalld-cmd 两个模式: --runtime:当前生效,重启后失效 --permanent:当前不生效,而重启后生效(firewall-cmd --reload:重启防火墙服务,使配置生效) 九个模版:

firewall-cmd --panic-on:紧急模式,断开全部网络连接



firewall-cmd --zone=public firewall-cmd --query-service=http -----查询runtime模式下http服务是否可用 firewall-cmd --permanent --query-service=http firewall-cmd --permanent --add-service=http --------添加http服务到permanent使之可用 firewall-cmd --permanent --reload--------重启防火墙服务使permanent模式下配置生效 firewall-cmd --permanent --remove-service=http -------移除http协议使之不可用 firewall-cmd --permanent --add-port=1000-2000/tcp -----添加端口号范围