0

Is it possible to redirect connections to a specific IP/port to an external IP/port?

Example:

Server A has the external IP xxx.xxx.xxx.xxx
Server B has the external IP yyy.yyy.yyy.yyy

User sends a request to server A on port 25565, I want to redirect it to server B at port 25565 but people who connect to server B must have theirs IP adressess, not IP adress of server A.

This works, but all people who connect has IP adress of server A and I need that they will have their own IP adresses.

iptables -t nat -A PREROUTING -p tcp --dport 25565 -j DNAT --to-destination xxx.xxx.xxx.xxx
iptables -t nat -A POSTROUTING -p tcp -d xxx.xxx.xxx.xxx --dport 25565 -j SNAT --to-source yyy.yyy.yyy.yyy
  • Using iptables -t nat -A PREROUTING -p tcp --dport 25565 -j MASQUERADE instead of second command does not work either :/ – Ondrej Simer Jan 27 '17 at 14:57
  • Some help please? :/ – Ondrej Simer Mar 9 '17 at 14:12
0

Using iptables -t nat -A PREROUTING -p tcp --dport 25565 -j MASQUERADE instead of second command does not work either :/

  • 1
    Please this should be an answer to the question, put all comments in your OP either as an update or a comment. – George Udosen Jan 27 '17 at 14:04
0

To accomplish this, you need DNAT on server A with the following rules:

iptables -t nat -A PREROUTING -p tcp --dport 25565 -j DNAT --to <server B IP> iptables -t nat -A POSTROUTING -p tcp --sport 25565 -j SNAT --to <server A IP>

Where:

  • <server A IP> is the IP address on Server A the client sees
  • <server B IP> is the IP address of host listening on tcp/25565

The first rule establishes: Client ---> Server A ---> Server B (requests)

And the second rule establishes: Server B ---> Server A ---> Client (responses)

Hope this helps

  • Hi, unfortunetaly, client doesn't connect with this. It has "signal" (I see that it is trying to connect), but that is all... On the other hand - thank you for help! :) – Ondrej Simer Jan 28 '17 at 18:04
  • Hmm.. Please edit original post to include the output of the following commands: iptables -t nat -vnL, iptables -vnL, route -n, and sysctl -a | grep net.ipv4.ip_forward" – maff1989 Jan 30 '17 at 14:43
  • pastebin.com/nLpjNtqu – Ondrej Simer Jan 30 '17 at 17:51
  • Are the clients connecting from the 10.8.0.0/24 (tun0) network? Or are they connecting from the Internet? – maff1989 Feb 14 '17 at 16:54
  • From the internet. – Ondrej Simer Feb 15 '17 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.