A
A
Anatoly2018-02-17 12:56:35
linux
Anatoly, 2018-02-17 12:56:35

How to redirect a port to another server while keeping the client's IP?

Hello!
There are two VPSs available:
On the first IP - 1.1.1.1
On the second IP - 2.2.2.2
The task is to direct the client from the first to the second, so that the second can see the client's IP. The appeal goes on port 9999.
The means of implementation are not important. At the moment, I have implemented a redirect using iptables, but the second VPS thinks that the first one (1.1.1.1) has connected to it, and not the client (7.7.7.7).
Current rules:

iptables -A FORWARD -d 2.2.2.2 -p udp -m udp --dport 9999 -j ACCEPT 
iptables -t nat -A PREROUTING -d 1.1.1.1 -p udp -m udp --dport 9999 -j DNAT --to-destination 2.2.2.2
iptables -t nat -I POSTROUTING -d 2.2.2.2 -p udp --dport 9999 -j SNAT --to-source 1.1.1.1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wexter, 2018-02-17
@Wexter

You lift VPN between servers. On the first one, you forward ports to the internal IP in the VPN, on the second server you raise PBR

V
Vladimir, 2018-03-16
@rostel

just don't add the POSTROUTING rule with --to-source

iptables -t nat -I POSTROUTING -d 2.2.2.2 -p udp --dport 9999 -j SNAT --to-source 1.1.1.1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question