在安装了Ubuntu服务器20.04和OpenVPN的VPS上,我需要将所有流量从VPN公共ip的特定端口转发到VPN客户端的同一个端口。
副总裁:
vps public ip: 1.1.1.1
vps vpn ip: 10.8.0.1客户IP:
vpn client ip: 10.8.0.2端口587的港口转发:
1.1.1.1:587 >> 10.8.0.2:587我尝试在VPS上运行这些命令(1.1.1.1):
sudo iptables -t nat -A PREROUTING -p tcp --dport 587 -j DNAT --to-destination 10.8.0.2:587
sudo iptables -t nat -A POSTROUTING -p tcp -d 10.8.0.2 --dport 587 -j SNAT --to-source 1.1.1.1但是,数据包没有被转发到ip 10.8.0.2。
您知道iptables应该如何配置才能进行正确的端口转发吗?
发布于 2023-02-27 22:07:48
我发现这一解决办法正如预期那样发挥作用:
sudo sysctl net.ipv4.ip_forward=1
sudo iptables -t nat -A PREROUTING -p tcp --dport 587 -j DNAT --to-destination 10.8.0.2:587
#exclude "lo" interface, otherwise dns service stop working
sudo iptables -t nat -A POSTROUTING ! -o lo -j MASQUERADEhttps://serverfault.com/questions/1123839
复制相似问题