我在Ubuntu 12.04.2 LTS
cat /proc/sys/net/ipv4/ip_forward 0
我用以下命令重置iptables:
iptables -F iptables -X iptables -t nat -F iptables -t nat -X iptables -t mangle -F iptables -t mangle -X iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT
我想redirect去往端口80的stream量到1337.这些命令完成:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 1337 iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-ports 1337
我继续下面的命令,以阻止除SSH之外的所有传入stream量,我期望端口redirect仍然有效:
iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -p tcp --dport ssh -j ACCEPT iptables -A INPUT -j DROP
但端口redirect不再起作用。
添加iptables -A INPUT -p tcp --dport 80 -j ACCEPT在iptables -A input -j DROP之前iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A input -j DROP也不能使其工作。
我还需要添加或更改什么?
为了防止1337的直接交通,你可以这样做:
iptables -A INPUT -p tcp -s 127.0.0.1/8 --dport 1337 -j ACCEPT所以只有来自主机本身的stream量(这是redirect)将被接受。