Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 192.168.0.1

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
1  
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 –  mtm Jan 4 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 at 8:31
    
It actually works if I try to connect via browser to an IP which isn't in the same network (192.168.10.10/24). But when I try to connect to something like "google.com" or "192.168.0.10" it doesn't work... Could somebody help me please? –  user2927980 Jan 9 at 19:19
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.