W
W
waltaki2020-08-14 19:40:41
linux
waltaki, 2020-08-14 19:40:41

How to forward a packet from IP:PORT to localhost:PORT?

External IP: 3.95.56.211
Local IP: 127.0.0.1
A process is started on 127.0.0.1 occupying UDP port 27884. It is necessary to redirect packets going to 3.95.56.211:27884 to 127.0.0.1:27884.
I have tried the following:

iptables -t nat -A PREROUTING --dst 3.95.56.211 -p udp --dport 27884 -j DNAT --to-destination 127.0.0.1

and this
iptables -t nat -A PREROUTING --dst 3.95.56.211 -p udp --dport 27884 -j DNAT --to-destination 127.0.0.1
iptables -I FORWARD 1 -i eno1 -o lo -d 127.0.0.1 -p udp -m udp --dport 27884 -j ACCEPT
iptables -t nat -A POSTROUTING --dst 127.0.0.1 -p udp --dport 27884 -j SNAT --to-source 3.95.56.211
iptables -t nat -A OUTPUT --dst 3.95.56.211 -p udp --dport 27884 -j DNAT --to-destination 127.0.0.1

But 0 results. Tell me how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-08-14
@waltaki

step 1.

iptables -t nat -I PREROUTING -p tcp -d 3.95.56.211/24 --dport 27884 -j DNAT --to-destination 127.0.0.1:27884

step 2.
sysctl -w net.ipv4.conf.eth0.route_localnet=1
don't forget to replace eth0 with the name of your external interface

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question