0

I have a local web server on 12345 port(can't change) and I want to forward port it from lo via iptables in command line. Forwarding is allowed.

`iptables -t nat -A PREROUTING -i lo -p tcp --dport 8080 -j DNAT --to-destination 10.0.2.15:12:125`

. No errors, but when I log in from the browser (127.0.0.1:8080) does not work. When I go to the ip server (10.0.2.15:12345) everything works fine. What am I doing wrong?

Sorry, if there are many mistakes in the text, it was translated from Ukrainian using Google Translate.

1
0

Scenario:

Web Server IP = 10.0.2.15 (eth0)
Hardcoded Listening Port = 12345/TCP
TCP Forward = from 10.0.2.15:8080 to 127.0.0.1:12345

Port forwarding from a standard NIC (eth0) to a loopback interface (lo) is disabled by default. Remove the previous iptables rules and execute the following:

# Forward any traffic destined to TCP 8080 on eth0 to 12345 on loopback
$ sudo iptables -t nat -I PREROUTING -p tcp -i eth0 --dport 8080 -j DNAT --to-destination 127.0.0.1:12345
# Then allow forwarding from standard NIC to loopback (assuming eth0 is the standard NIC)
$ sudo sysctl -w net.ipv4.conf.eth0.route_localnet=1
4
  • I fixed the error But nothing has changed. I entered your command. `` No chain / target / match by that name. `` What does this mean? – BBapps 1posn Oct 17 '20 at 17:01
  • Please edit your original question so people can understand your current issue and assist you. – Bruce Malaudzi Oct 17 '20 at 18:00
  • I have edited the answer and it worked 100% when I tested. Please accept if all works fine – Bruce Malaudzi Oct 17 '20 at 18:39
  • You misunderstood me. Web Server IP = 10.0.2.15 (usbnet0 -local) TCP Forward = from 10.0.2.15:12345 to 127.0.0.1:8080 My web-server on local ip – BBapps 1posn Oct 18 '20 at 7:16

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.