I have services running on VPS A(1.1.1.1) on ports 30000-32000.
I would like to have VPS B(2.2.2.2) to port forward them to 20000- 22000.
(You may take a look at the demo graph link below to understand what I would like to achieve :D )
I used the command below to set up iptables:
iptables -t nat -A PREROUTING -p tcp --dport 20000:22000 -j DNAT --to-destination 1.1.1.1:30000-32000
iptables -t nat -A POSTROUTING -p tcp -d 1.1.1.1 --dport 30000:32000 -j SNAT --to-source 2.2.2.2
20000:22000
iptables -t nat -A PREROUTING -p udp --dport 20000:22000 -j DNAT --to-destination 1.1.1.1:30000-32000
iptables -t nat -A POSTROUTING -p udp -d 1.1.1.1 --dport 30000:32000 -j SNAT --to-source 2.2.2.2
20000:22000
After some tests, I find that it seems that only port 20000 was forwarding the original server's port 30000. However, other ports are not working.
I checked 4 things below: 1. VPS A (1.1.1.1)'s service Service running on ports 30000 - 32000 are fully functional
- VPS B port forwarding setting Upon checking sysctl on VPS B, ipv4 forwarding is enabled.
(i.e. net.ipv4.ip_forward = 1
)
- VPS B's iptable setting. It looks fine to me. You may click on the link below for exact setting.
- I also tried to do a normal multiple port forwarding from VPS A to VPS B (i.e. VPS A (30000-32000) >> VPS B (30000-32000))
(You may take a look at the demo graph link below for what I would like to achieve :D )
Everything is working fine.
I really have no idea how to achieve it. Any help is appreciated! Thank you in advance!