内核记得先打开转发功能
echo "net.ipv4.conf.eth0.forwarding = 1">>/etc/sysctl.conf
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "net.ipv4.ip_forward=1">>/etc/sysctl.conf
sysctl -p
然后设置端口转发
iptables -t nat -I PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 172.17.0.100:8080
iptables -I FORWARD -p tcp -d 172.17.0.100 --dport 8080 -j ACCEPT
iptables-save
Q.E.D.