Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use a Linux machine as WLAN Router with the help of hostapd and udhcpd. There's also an Apache web server installed on the same machine.

Now I want to redirect all the traffic which comes through port 80 from wlan0 to the the Apache webserver.

iptables -t mangle -N internet
iptables -t mangle -A PREROUTING -i wlan0 -p tcp -m tcp --dport 80 -j internet
iptables -t mangle -A internet -j MARK --set-mark 99
iptables -t nat -A PREROUTING -i wlan0 -p tcp -m mark --mark 99 -m tcp --dport 80 -j DNAT --to-destination

This was the solution I've found. I've adjusted the IP and the interface, but it didn't work. Any ideas?

share|improve this question
Are there packets being matched by the mangle and NAT rules when you generate the required traffic? sudo iptables -t mangle -L -v sudo iptables -t nat -L -v – Matt Jan 4 '14 at 16:18
Normally you'd use -j REDIRECT here, I think (but both should work). Also you have a lot of extra complexity—what is with the mark? Have you actually tested with this minimal example? – derobert Jan 5 '14 at 8:31
It actually works if I try to connect via browser to an IP which isn't in the same network ( But when I try to connect to something like "google.com" or "" it doesn't work... Could somebody help me please? – user2927980 Jan 9 '14 at 19:19
I have the same need and I haven't been able to find anything about this subject on the www. I have hostapd running and serving ipaddresses over the WiFi but I need to connect to local host. – Bob Brunius Apr 11 '15 at 5:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.