I am trying to do something very simple. I am trying to force all web request to go to my local webserver. I start by activating said webserver on my Kali Linux VirtualBox machine

sudo systemctl start apache2

Then I redirect all web traffic with iptables

sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination

Check to make sure the changes took effect

sudo iptables -t nat -L

They did

target     prot opt source               destination         
DNAT       tcp  --  anywhere             anywhere             tcp dpt:https to:

Now when I go to google.com or even example.com I just go to google.com as I normally would. How can I make the changes actually take effect?


When you go to google.com, your packet never visit PREROUTING chain. Use OUTPUT instead.enter image description here

  • I tried your suggestion. sudo iptables -t nat -A OUTPUT -p tcp --dport 443 -j DNAT --to-destination sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination . But after doing sudo iptables -L it looks like the output command is not being added. What did I do wrong? – user21303 Nov 13 '18 at 7:31
  • Wait, nevermind. It's working. – user21303 Nov 13 '18 at 7:41
  • I'm receiving an error stating that this site can not provide a secure connection. I suppose I should not be surprised when considering HTTPS. Which begs the question, how do coffee shops redirect users to the terms of service page people need to agree to before they start using the internet? – user21303 Nov 13 '18 at 7:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.