今天,我能夠將一些遊戲伺服器遷移到另一台伺服器,並且需要一些幫助將流量從舊 IP 重定向到新 IP。
伺服器1 1.1.1.1 -----(網際網路)----->伺服器2.2.2.2
我假設使用 iptables 來執行此操作,因為它在 server1 中的 centOS 機器上使用了此規則。
/etc/sysctl.conf:net.ipv4.ip_forward = 1
iptables -t nat -A PREROUTING -p udp --dest 1.1.1.1 --dport 27015 -j DNAT --to-destination 2.2.2.2:27015
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -t nat -A POSTROUTING -d 2.2.2.2 -p udp --dport 27015 -j SNAT --to 1.1.1.1
但用戶端無法從舊 IP 連線到伺服器,重定向未啟動。
答案1
你可以按照這些思路做些事情:
iptables -t nat -A OUTPUT -p all -d 1.1.1.1 -j DNAT --to-destination 2.2.2.2
iptables -t nat -A POSTROUTING -p all -j MASQUERADE
答案2
如果您之前在此伺服器上沒有配置任何 NAT,則可能沒有將核心設定為傳遞 IPv4 流量。
確保您的/etc/sysctl.conf
:
net.ipv4.ip_forward = 1