#系统
centos6.8
[root@root ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
#防火墙
[root@root ~]# rpm -qa | grep iptables
iptables-1.4.7-16.el6.x86_64
iptables-ipv6-1.4.7-16.el6.x86_64
#iptables防火墙配置文件
[root@root ~]# vim /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
#-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --sport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --sport 53 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp --dport 22 -s 192.168.1.1 -j ACCEPT
-A INPUT -p tcp --dport 22 -j DROP
COMMIT
#说明
-A INPUT:表示将规则添加到INPUT链中,即针对输入流量的规则。
-m state --state NEW:使用state模块,匹配状态为NEW的数据包,即新建的连接。
-m tcp -p tcp:使用tcp模块,匹配TCP协议的数据包。
–dport 53:匹配目标端口号为53的数据包,即DNS服务的默认端口号。
-j ACCEPT:如果以上条件匹配,则接受该数据包。
#说明
-A INPUT -p tcp --dport 22 -s 192.168.1.1 -j ACCEPT
22端口ssh限制源IP192.168.1.1
#启动iptables/重启启动iptables
service iptables start
service iptables restart
#设置开机自启
chkconfig iptables on
#查看开机自启
chkconfig --list | grep iptables
#检查iptables配置
iptables -L