我必须设置一个规则,使我的Web服务器(在端口7000上运行)可以在端口80上访问:
ptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 7000
迄今为止,这是完美的。
但是,如果我重新启动服务器的规则不见了。 有什么做的做这个规则永久?
埃利亚斯
你使用哪种GNU / Linux发行版?
对于Debian / Ubuntu,简单的解决scheme是将iptables调用添加到/etc/network/interfaces的post-up钩子中,如下所示:
# The primary network interface auto eth0 iface eth0 inet dhcp post-up iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 7000
在基于Red Hat / Fedora的系统上:
service iptables save
并确保iptables服务设置为在启动时启动:chkconfig iptables on
基本上,您将iptables命令添加到networking启动脚本,以便在networking连接启动时运行。
所需文件的变化从发行版到发行版有所不同。
如果您使用的是Ubuntu(也可能是Debian等),您可以使用命令iptables-save和iptables-restore在重新启动时保存configuration。
你可以添加这行到/etc/conf.d/local.start
不要反复调用iptables,我build议以下步骤:
[1]根据自己的喜好configurationiptables(块,反歧视,redirect等)
[2]保存iptablesconfiguration:
iptables-save > /etc/my-iptables.conf
(或使用你喜欢的名字)
[3]创build一个包含这些行的脚本(例如/etc/my-iptables-init.sh ):
#!/bin/bash iptrest="<location_of_iptables-restore>" cat="/bin/cat" conf="/etc/my-iptables.conf" # $cat $conf | $iptrest
(有人说iptables-restore < /etc/my-iptables.con有时不起作用)
[4]从任何你想要的地方调用脚本。 也许/ etc / network / interfaces或(我的首选)/etc/rc.local