0

I am using the following command to forward incoming traffic from port 30 to port 1234. But it's not working. In Wireshark also there is no trace of packets directing to port 1234 are found.

sudo iptables -t nat -I PREROUTING --src 0/0 --dst 127.0.0.1 -p tcp --dport 30 -j REDIRECT --to-ports 1234.

bumped to the homepage by Community 17 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • Look at the kernel ip forwarding settings i.e. by running the command "sysctl -ar forward" Make sure that the relevant settings are enabled. For example, if you are using IP version 4, ensure that "net.ipv4.conf.all.forwarding" is set to 1 – Raman Sailopal Jul 20 '18 at 9:16
  • Yes. net.ipv4.ip_forward is also set to 1 and also uncommented at the system variable file(/etc/sysctl.conf) to allow forwarding. But still doesn't seem to work. – SRNB Jul 20 '18 at 11:30
1

Local forwarding of packets different port doesn't pass through PREROUTING chain. They follow the OUTPUT chain. Changing the chain from PREROUTING TO OUTPUT works.

sudo iptables -t nat -A OUTPUT -p tcp --dport 30 -j REDIRECT --to-port 1234.

More details can be found here about the iptables NAT Filtershttps://www.karlrupp.net/en/computer/nat_tutorial

0

check if this is enabled or not by

sudo iptables -t nat -L

If There are any entries , delete them using:

sudo iptables -F -t nat

Try without src dest flags:

sudo iptables -t nat -A PREROUTING -p tcp --dport 30 -j REDIRECT --to-ports 1234

check again if this is enabled or not by

sudo iptables -t nat -L

It is Important to remove chained entries queued by default to "OUTPUT" route.

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.