我正在尝试使用IPtables将端口80重定向到内部IP (192.168.33.52)。但是如果使用端口80打开tcpdump,我会看到:
04:36:59.848744 IP 1.2.3.4.59936 > 192.168.33.52.http:标志S,序号2560507980,win8192,选项MS1460,nop,wscale 8,nop,nop,sackOK,长度0
如何将我们的公网IP 1.2.3.4重写为我们的实习生IP 192.168.33.200?192.168.33.200将流量重定向回客户端?
网络接口:
eth0 - 1.2.3.4 (公网IP) eth0:0 - 192.168.33.200 (内网IP)
网站服务器: 192.168.33.52
我的iptables规则:
目标端口选择源目的
DNAT tcp -- 0.0.0.0/0 1.2.3.4 tcp dpt:80到:192.168.33.52:80
链输入(策略接受)目标端口选择源目标
链输出(策略接受)目标端口选择源目标
链发布(策略接受)
目标端口选择源目的
SNAT tcp -- 0.0.0.0/0 192.168.33.52至:1.2.3.4
发布于 2017-07-04 20:40:54
将下面的脚本保存为script.sh,然后使其可执行(chmod +x script.sh),然后使用./script.sh运行它
您需要的iptables规则如下:
#!/bin/bash
# enable ip forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# define vars
LOCALNET="192.168.33.0/24"
WAN="eth0"
WANIP="PUBLIC_IP"
WEBSERVER="192.168.33.52"
# enable traffic from the local network to the internet
iptables -t nat -A POSTROUTING -s $LOCALNET -o $WAN -j MASQUERADE
# HTTP to the local web server from the outside world
iptables -t nat -A PREROUTING -d $WANIP -p tcp --dport 80 -j DNAT --to-destination $WEBSERVER:80
iptables -t nat -A POSTROUTING -d $WEBSERVER -p tcp --dport 80 -j MASQUERADEhttps://stackoverflow.com/questions/44775857
复制相似问题