S
S
Sergey Vasiliev2021-06-20 15:04:03
iptables
Sergey Vasiliev, 2021-06-20 15:04:03

How to redirect traffic from 1 machine to 2?

Good day. What is the point, there is a client with ip 123.xxx and 2 servers with ip 1.xxx and 2.xxx The client sends a request to 1.xxx and you need 1.xxx to redirect all traffic to 2.xxx and also in reverse order. i created 2 iptables entries:

iptables -t nat -A PREROUTING -d 2.xxx -p tcp -j DNAT --to-destination 1.xxx

iptables -t nat -A POSTROUTING -d 1.xxx -p tcp -j SNAT - to-source 2.xxx

As a matter of fact everything works, but there is 1 problem. 2.xxx receives traffic from ip 1.xxx, but it needs to be received from the client's ip (123.xxx) I would be very grateful if you could help me solve the problem. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-06-20
@hint000

and you need to receive from the client's IP
It doesn't work like that. I explain why not.
If 2.xxx receives from 123.xxx, then he must answer to 123.xxx
And if he answers to 123.xxx, then 123.xxx will receive a response from 2.xxx, and he sent the request to 1.xxx, so that the response from some left server will fly into the trash.
Write what problem you are trying to solve in this way, maybe there is a better solution. For example, a reverse proxy, if the conditions of the problem allow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question