需求:
java 服务: 10.16.0.186:7000 (udp 端口)
配置的转发机器: 外网ip(1.2.3.4) 内网ip(10.16.0.95) udp端口: 27001
iptables 开启转发功能:
echo 1 >/proc/sys/net/ipv4/ip_forward
sysctl -p
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A PREROUTING -p udp -m udp --dport 27001 -j DNAT --to-destination 10.16.0.186:7000
iptables -t nat -A POSTROUTING -d 10.16.0.186 -p udp -m udp --dport 7000 -j SNAT --to-source 10.16.0.95
用 tcpdump udp port 27001 -n 抓包发现:
10.16.0.186 会将数据包返回至 10.16.0.95
10.16.0.95 会将数据包返回至 客户端
数据包之间有交互就是对的