Linux下iptables防火墙的设定
Linux下防火墙的设定
安装linux后(防火墙是开启状态),需要检查防火墙端口
1.iptables防火墙启动和停止
启动iptables防火墙时命令行输入 #service iptables start
[root@ ~]# service iptables start应用 iptables 防火墙规则: [确定]载入额外 iptables 模块:ip_conntrack_netbios_ns [确定]
要停止iptables命令行输入 #service iptables stop
[root@ ~]# service iptables stop清除防火墙规则: [确定]把 chains 设置为 ACCEPT 策略:filter [确定]正在卸载 Iiptables 模块: [确定]
2.查看iptables的状态
命令行输入?#service iptables status
[root@ ~]# service iptables status表格:filterChain INPUT policy ACCEPT num target prot opt source destination1 RH-Firewall-1-INPUT all -- /0 /0 Chain FORWARD policy ACCEPT num target prot opt source destination1 RH-Firewall-1-INPUT all -- /0 /0 Chain OUTPUT policy ACCEPT num target prot opt source destination Chain RH-Firewall-1-INPUT 2 references num target prot opt source destination1 ACCEPT all -- /0 /02 ACCEPT icmp -- /0 /0 icmp type 2553 ACCEPT esp -- /0 /04 ACCEPT ah -- /0 /05 ACCEPT udp -- /0 51 udp dpt:53536 ACCEPT udp -- /0 /0 udp dpt:6317 ACCEPT tcp -- /0 /0 tcp dpt:6318 ACCEPT all -- /0 /0 state RELATED,ESTABLISHED9 ACCEPT tcp -- /0 /0 state NEW tcp dpt:2210 ACCEPT tcp -- /0 /0 state NEW tcp dpt:2311 ACCEPT tcp -- /0 /0 state NEW tcp dpt:8012??? ACCEPT tcp? --? /0 /0 state NEW tcp dpt:11013 ACCEPT tcp -- /0 /0 state NEW tcp dpt:44314 REJECT all -- /0 /0 reject-with icmp-host-prohibited
*上面的输出显示了防火墙处于开启状态,并打开了22,23,80,110, 443端口
3.查看iptables规则集
要查看系统中现有的iptables规则集,可以运行以下命令:
iptables --list
4.清除原有防火墙规则.
不管你在安装linux时是否启动了防火墙,如果你想配置属于自己的防火墙,那就清除现在filter的所有规则.
[root@ ~]# iptables -F 清除预设表filter中的所有规则链的规则[root@ ~]# iptables -X 清除预设表filter中使用者自定链中的规则
查看本机关于IPTABLES的设置情况
iptables -L -n
现在和安装linux时没有启动防火墙一样了.这些防火墙配置重起就会失去作用,当需要保存时使用如下命令
/etc/rc.d/init.d/iptables save
这样就可以写到/etc/sysconfig/iptables文件里了.写入后记得把防火墙重起一下,才能起作用.
service iptables restart
4.开机后自启动防火墙的设定
命令行输入?#ntsysv
[root@?~]# ntsysv
在gui中选上iptables后。确认
5.简单配置防火墙规则
[root@?~]# setup
选择 防火墙配置–》定制–》在“其他端口”中输入要开放的端口, 例:1723