Linux下IPTABLES防火墙的设定

安装linux后(防火墙是开启状态),需要检查防火墙端口

1.iptables防火墙启动和停止

   启动iptables防火墙时命令行输入 #service iptables start

[[email protected] ~]# service iptables start

应用 iptables 防火墙规则:                                  [确定]

载入额外 iptables 模块:ip_conntrack_netbios_ns             [确定]

   要停止iptables命令行输入 #service iptables stop

[[email protected] ~]# service iptables stop

清除防火墙规则:                                            [确定]

把 chains 设置为 ACCEPT 策略:filter                        [确定]

正在卸载 Iiptables 模块:                                   [确定]

2.查看iptables的状态

   命令行输入 #service iptables status

[[email protected] ~]# service iptables status

表格:filter

Chain INPUT (policy ACCEPT)

num   target      prot opt source                destination

1     RH-Firewall-1-INPUT   all  --  0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT)

num   target      prot opt source                destination

1     RH-Firewall-1-INPUT   all  --  0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)

num   target      prot opt source                destination         

Chain RH-Firewall-1-INPUT (2 references)

num   target      prot opt source                destination

1     ACCEPT      all  --  0.0.0.0/0            0.0.0.0/0

2     ACCEPT      icmp --  0.0.0.0/0            0.0.0.0/0            icmp type 255

3     ACCEPT      esp  --  0.0.0.0/0            0.0.0.0/0

4     ACCEPT      ah   --  0.0.0.0/0            0.0.0.0/0

5     ACCEPT      udp  --  0.0.0.0/0            224.0.0.251          udp dpt:5353

6     ACCEPT      udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:631

7     ACCEPT      tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:631

8     ACCEPT      all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

9     ACCEPT      tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22

10    ACCEPT      tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:23

11    ACCEPT      tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80

12    ACCEPT      tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:110

13    ACCEPT      tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:443

14    REJECT      all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

*上面的输出显示了防火墙处于开启状态,并打开了22,23,80,110, 443端口

3.查看iptables规则集

要查看系统中现有的iptables规则集,可以运行以下命令:

iptables --list

4.清除原有防火墙规则.

不管你在安装linux时是否启动了防火墙,如果你想配置属于自己的防火墙,那就清除现在filter的所有规则.

[[email protected]  ~]# iptables -F 清除预设表filter中的所有规则链的规则

[[email protected]  ~]# iptables -X 清除预设表filter中使用者自定链中的规则

查看本机关于IPTABLES的设置情况

iptables -L -n

现在和安装linux时没有启动防火墙一样了.这些防火墙配置重起就会失去作用,当需要保存时使用如下命令

/etc/rc.d/init.d/iptables save

这样就可以写到/etc/sysconfig/iptables文件里了.写入后记得把防火墙重起一下,才能起作用.

service iptables restart

4.开机后自启动防火墙的设定

   命令行输入 #ntsysv

[[email protected] ~]# ntsysv

在gui中选上iptables后。确认

5.简单配置防火墙规则

[[email protected] ~]# setup

选择 防火墙配置–》定制–》在“其他端口”中输入要开放的端口, 例:1723

参考资料:

http://www.jefflei.com/post/1760.html

猜你喜欢

转载自zhb1208.iteye.com/blog/1330722