If I have two Virtual Private Servers and they are located in different countries. Then I want to use one server (139.162.131.242) as a proxy server to proxy tcp and udp traffic, the proxy process listens on local port 8300. Another server (172.104.98.95) will be used to relay the traffic to the proxy server.
Someone taught me how to achieve this by using IPTABLES:
STEP 1: set up the proxy program on the proxy server (139.162.131.242) and run it
STEP 2: write a few iptables rules on the relay server (172.104.98.95), like this:
iptables -t nat -A PREROUTING -p tcp --dport 8300 -j DNAT --to-destination 139.162.131.242:8300
iptables -t nat -A PREROUTING -p udp --dport 8300 -j DNAT --to-destination 139.162.131.242:8300
iptables -t nat -A POSTROUTING -d 139.162.131.242 -p tcp --dport 8300 -j SNAT --to-source 172.104.98.95
iptables -t nat -A POSTROUTING -d 139.162.131.242 -p udp --dport 8300 -j SNAT --to-source 172.104.98.95
STEP 3: set up the proxy client program to make all tcp and udp traffic go to the relay server
But I am confused about this method. For example, I am playing a online game that use udp or tcp to communicate with the game server. When these traffic arrive the relay server, they will be DNATed and finally arrive the proxy server, but can the proxy server know where these traffic be sent to? I mean will the proxy server send these traffic to the game server? If it will, how can the proxy server know the real game server address after the destination address of the traffic has already been changed on the relay server?