Answer the question
In order to leave comments, you need to log in
How to redirect traffic along with client ip?
Hello.
It was necessary to temporarily redirect traffic from the port of one machine to another. Through iptables, this is done simply: iptables -t nat -A PREROUTING -p 11111 --dport port -j DNAT --to-destination 1.2.3.4:11111
iptables -t nat -A POSTROUTING -j MASQUERADE
Everything works, but there is one BUT (quite logical), on the machine where the traffic is redirected, the ip of the machine on which the redirection is redirected, and not the ip of the client.
ip to be redirected to is not on the same network!
Is it possible to redirect traffic with the original ip of the client, and if so, how?
Answer the question
In order to leave comments, you need to log in
Here it is:
iptables -t nat -A POSTROUTING -j MASQUERADE
replaces the Source IP address of all outgoing packets with the IP of this machine. Remove this rule (or limit its scope) - it will not be substituted.
But you need to make sure that the reverse traffic also goes through the same machine that replaces the addresses, at least for protocols with two-way data exchange. Without it, everything will break.
If there is syslog or other "one-way" udp protocols, then it will be fine.
Or, if possible, use a proxy and L7 protocol tools like the X-Forwarded-For header.
If I'm not mistaken, you're doing a forwarding, not a redirect. For a redirect, there is a REDIRECT command for the local network.
Your situation is described here - www.debuntu.org/how-to-redirecting-network-traffic...
You need traffic mirroring.
You need to use --tee. More on Habré:
m.habrahabr.ru/post/55256
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question