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`

. No errors, but when I log in from the browser ( does not work. When I go to the ip server ( 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.



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

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
# Then allow forwarding from standard NIC to loopback (assuming eth0 is the standard NIC)
$ sudo sysctl -w net.ipv4.conf.eth0.route_localnet=1
  • 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 = (usbnet0 -local) TCP Forward = from to 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.