I have an ubuntu pc and an android phone conneted to my router through a cable and wi-fi respectively. I set the android phone to use a proxy my-wan-ip:5555 and enabled port forwarding on my router on port 5555 to my ubuntu pc. I want all http/https connections from port 5555 to be forwarded to the internet, I tried the following but it didn't work:

iptables -F
iptables -t nat -F
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 5555 -j REDIRECT --to-port 80
iptables -A FORWARD -i eth0 -p tcp --dport 80 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -p tcp --dport 80 -j MASQUERADE
echo '1' | tee /proc/sys/net/ipv4/ip_forward

I'm not sure but it seems to me that the sent packets are received on my pc but nothing is sent back, (i can see the received packets on wireshark and tcpdump), how do i fix it?


  1. Also i just noticed that after adding these rules i can't connect to the internet on my pc.
  2. I have ufw installed on my PC, not sure if it's affecting anything.
  3. I have apache webserver installed as well and port forwaring enabled on port 80 to my ubuntu pc.
  • 1
    You need to be clear about "to" and "from". You are sending traffic from your phone to port 5555, then you say you want to do something with all connections from port 5555. Do you actually have a (http) proxy installed somewhere? Port forwarding from 5555 to 80 doesn't constitute proxying. Perhaps edit your question to state what you are trying to accomplish. – wurtel Nov 16 '15 at 13:30
  • @wurtel I want my pc to work as proxy forwarding traffic from port 5555 to the internet just like squid does but using iptables only. – razzak Nov 16 '15 at 18:07
  • That won't work because squid uses the url passed by the client to determine what host to connect to. That can't be done with iptables. – wurtel Nov 18 '15 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.