以下所有命令都按预期工作。 我发布这只是为了确保我没有做可能会影响其他服务的东西。 我有两个问题:
1)我注意到有一些防火墙规则是默认的。 为什么我再也看不到他们了?
2)即使在停止服务之后,iptables如何工作?
[root@server home]# /etc/init.d/iptables status Table: 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 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited [root@server home]# /etc/init.d/iptables stop Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: filter [ OK ] Unloading iptables modules: [ OK ] [root@server home]# /sbin/iptables -t nat -I PREROUTING -s ! 127.0.0.1 -p tcp --dport 3306 -j REDIRECT --to-ports 4040 [root@server home]# echo $? 0 [root@server home]# /etc/init.d/iptables status Table: nat Chain PREROUTING (policy ACCEPT) num target prot opt source destination 1 REDIRECT tcp -- !127.0.0.1 0.0.0.0/0 tcp dpt:3306 redir ports 4040 Chain POSTROUTING (policy ACCEPT) num target prot opt source destination Chain OUTPUT (policy ACCEPT) num target prot opt source destination [root@server home]# /sbin/iptables -t nat -D PREROUTING -s ! 127.0.0.1 -p tcp --dport 3306 -j REDIRECT --to-ports 4040 [root@server home]# echo $? 0 [root@server home]# /etc/init.d/iptables status Table: nat Chain PREROUTING (policy ACCEPT) num target prot opt source destination Chain POSTROUTING (policy ACCEPT) num target prot opt source destination Chain OUTPUT (policy ACCEPT) num target prot opt source destination
iptables实际上不是一个像apache这样的服务。 iptables是Netfilter内核防火墙的用户界面。 所以通过停止iptables“服务”,你实际上只是卸载所有的防火墙规则,并将默认策略设置为ACCEPT 。
至于你默认的第一个有关规则的问题,你需要查看你的发行版的iptablesconfiguration文件。 如果您使用的是基于RHEL的发行版,那么该文件通常是/etc/sysconfig/iptables 。 这些规则没有显示的原因是因为当你停止iptables“服务”时,它们全部从防火墙configuration中被刷新。 所有需要持久保存的防火墙规则都需要添加到该文件中。 如果你在命令行中添加一个iptables规则,那么当iptables下一次重启或者服务器重启时它会丢失。