I’m trying to do a simple port forwarding – direct all traffic received on port 80 to port 32078.
When I run the below command, I can clearly receive requests on port 80:
<code>sudo netcat -l 80
(after sending request)
GET / HTTP/1.1
User-Agent: PostmanRuntime/7.37.3
Accept: */*
Postman-Token: 3f0056ba-5de9-4ef8-9ee7-34a3bcdf6cb5
Host: sshrout-ubuntu
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
</code>
<code>sudo netcat -l 80
(after sending request)
GET / HTTP/1.1
User-Agent: PostmanRuntime/7.37.3
Accept: */*
Postman-Token: 3f0056ba-5de9-4ef8-9ee7-34a3bcdf6cb5
Host: sshrout-ubuntu
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
</code>
sudo netcat -l 80
(after sending request)
GET / HTTP/1.1
User-Agent: PostmanRuntime/7.37.3
Accept: */*
Postman-Token: 3f0056ba-5de9-4ef8-9ee7-34a3bcdf6cb5
Host: sshrout-ubuntu
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
I then add a rule in iptables:
<code>sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 32078
</code>
<code>sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 32078
</code>
sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 32078
Now if I try to listen on port 32078:
<code>sudo netcat -l 32078
</code>
<code>sudo netcat -l 32078
</code>
sudo netcat -l 32078
I am unable to see anything received when I make an HTTP request to port 80.
My initial inclination was that there was likely some rule in the PREROUTING or INPUT tables interfering with it so I even deleted all other rules from these tables, but still am unable to see the traffic.
<code>sudo iptables -t nat -L PREROUTING
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 32078
sudo iptables -t nat -L INPUT
Chain INPUT (policy ACCEPT)
target prot opt source destination
</code>
<code>sudo iptables -t nat -L PREROUTING
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 32078
sudo iptables -t nat -L INPUT
Chain INPUT (policy ACCEPT)
target prot opt source destination
</code>
sudo iptables -t nat -L PREROUTING
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 32078
sudo iptables -t nat -L INPUT
Chain INPUT (policy ACCEPT)
target prot opt source destination