0

I'm trying to redirect all the browser's requests from my wifi interface wlan1 to a captive portal. I have a node web server running on my target on 10.4.30.34:4040.

It has to redirect the browser directly to the web server, on the good port, like I entered "10.4.30.34:4040" in the location bar.

For now, it only redirects to the first page of the web server but when I try to navigate through the widgets, nothing happen, like it redirects only the first request.

In addition, it does redirect only when the target is connected to internet. I supposed that it's because the dns server is missing when it's disconnected so I need to have my own DNS server running and redirect the dns requests.

Here's my iptables :

# Completed on Tue Mar  8 09:19:04 2016
# Generated by iptables-save v1.4.21 on Tue Mar  8 09:19:04 2016
*nat
:PREROUTING ACCEPT [9574:1494526]
:INPUT ACCEPT [4431:653511]
:OUTPUT ACCEPT [101:17500]
:POSTROUTING ACCEPT [47:8227]
-A PREROUTING -i br0 -p tcp -m mark --mark 0x63 -m tcp --dport 80 -j DNAT --to-destination 10.4.30.34:4040
-A PREROUTING -i br0 -p tcp -m mark --mark 0x63 -m tcp --dport 443 -j DNAT --to-destination 10.4.30.34:4040
-A POSTROUTING -o eth1 -j MASQUERADE
-A POSTROUTING -o wlan0 -j MASQUERADE
COMMIT
# Completed on Tue Mar  8 09:19:04 2016
# Generated by iptables-save v1.4.21 on Tue Mar  8 09:19:04 2016
*mangle
:PREROUTING ACCEPT [47457:9766851]
:INPUT ACCEPT [37596:7677987]
:FORWARD ACCEPT [5111:1392701]
:OUTPUT ACCEPT [16333:6011533]
:POSTROUTING ACCEPT [21605:7471587]
:internet - [0:0]
-A PREROUTING -i br0 -p tcp -m tcp --dport 80 -j internet
-A PREROUTING -i br0 -p tcp -m tcp --dport 443 -j internet
-A internet -j MARK --set-xmark 0x63/0xffffffff
COMMIT
# Completed on Tue Mar  8 09:19:04 2016
# Generated by iptables-save v1.4.21 on Tue Mar  8 09:19:04 2016
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -j ACCEPT
-A FORWARD -j ACCEPT
-A OUTPUT -j ACCEPT
COMMIT
# Completed on Tue Mar  8 09:19:04 2016

My /etc/resolv.conf :

nameserver 8.8.8.8
nameserver 8.8.4.4

I installed dnsmasq & bind, I followed this tutorial : http://openexhibits.org/wp-content/uploads/2012/05/CaptivePortalHowto.pdf

But it didn't work...

Thank you

0

Here's the solution :

1- Install a bind server as a local dns that will always return the same IP address

2- Redirect DNS requests to bind.

iptables -A PREROUTING -i br0 -p tcp -m mark --mark 0x63 -m tcp --dport 53 -j DNAT --to 10.4.30.34
iptables -A PREROUTING -i br0 -p udp -m mark --mark 0x63 -m udp --dport 53 -j DNAT --to 10.4.30.34
iptables -A PREROUTING -i br0 -p tcp -m tcp --dport 53 -j internet
iptables -A PREROUTING -i br0 -p udp -m udp --dport 53 -j internet
iptables -A internet -j MARK --set-xmark 0x63/0xffffffff

3- Install lighttpd that will redirect all internet requests on a specific URL

/etc/lighttpd.conf : 

server.modules          = ( "mod_redirect", "mod_rewrite" )
server.document-root    = "/www/pages/"
server.port             = 80

url.redirect = ( "^/(.*)$" => "http://10.4.30.34:4040" )

Your Answer

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

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