searj6
Posts: 3
Joined: Sun Oct 26, 2014 8:39 pm

Captive Portal - Redirect all IP to Single IP

Sun Oct 26, 2014 8:50 pm

Hi

I'm trying to set up a 'captive portal' type pi webserver. Once someone connects to my Raspberry Pi I'd like them to be redirected to a locally hosted webpage. The pi doesn't have an internet connection - so it's closer to something like the PirateBox.

So I've been following a whole host of different tutorials on creating 'captive portals' on linux / pi - and have most of it working. Well, I have the DHCP working and I can serve pages with lighttpd (or node) and if hit the correct IP address you get re-directed to the default page.

However, the bit I can't get is iptables to redirect all incoming traffic to a single IP address. I've tried countless different ways with no joy - so I feel like I might be missing something else.

wlan0 is my wifi
192.168.42.1 is the pi's address

Here's one of the many attempts I've made to get it working:

Code: Select all

sudo iptables -t mangle -N internet
sudo iptables -t mangle -A PREROUTING -i wlan0 -p tcp -m tcp --dport 80 -j internet
sudo iptables -t mangle -A internet -j MARK --set-mark 99
sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp -m mark --mark 99 -m tcp --dport 80 -j DNAT --to-destination 192.168.42.1
Can anyway spot what I'm doing wrong or if I've managed to break some other part of the install with all my attempts at 'fixing' this.

Many thanks for any suggestions!

searj6
Posts: 3
Joined: Sun Oct 26, 2014 8:39 pm

Re: Captive Portal - Redirect all IP to Single IP

Sun Oct 26, 2014 9:56 pm

hmmm - I've made a bit of progress which is to install a DNS. DNSMASQ (and disabled the DHCP part). I can redirect web requests to my server - but not IP addresses (obviously).

I still think that I should be able to do this at the IPTables level - but appear to have got in a twist somewhere.

This will also open the can of worms - how to get (Android / IPhone) redirectly correctly when they search for a Login page. And also google search (I'm testing on android) gets very upset with me as it thinks I'm hacking the phone :)

User avatar
default_user8
Posts: 528
Joined: Mon Nov 18, 2013 3:11 am

Re: Captive Portal - Redirect all IP to Single IP

Sun Oct 26, 2014 11:34 pm

I suggested this to another person, and he got it working on his pi. You can run open wrt on your pi and use chillispot as your captive portal.
http://www.raspberrypi.org/forums/viewt ... rt#p598902
Hope this helps.
Two heads are better than one, unless one's a goat head.

searj6
Posts: 3
Joined: Sun Oct 26, 2014 8:39 pm

Re: Captive Portal - Redirect all IP to Single IP

Wed Oct 29, 2014 12:33 pm

Thanks - I didn't see that post when I was searching through the history.

It seems a little overkill for the 'quite basic' thing I'm trying to do - but thanks for an angle for me investigate. I'll take a look over the weekend.

User avatar
default_user8
Posts: 528
Joined: Mon Nov 18, 2013 3:11 am

Re: Captive Portal - Redirect all IP to Single IP

Wed Oct 29, 2014 1:55 pm

I get that, but there is nothing "quite basic" about capturing all ip request and redirecting them to a specific web address. And yes google is very picky about how you redirect their web searches. They don't like not being able to moniter what you look at, it prevents them from selling your search tendancies to advertisers. Try and use google with TOR. :lol:
Two heads are better than one, unless one's a goat head.

lunix15
Posts: 1
Joined: Fri Oct 17, 2014 10:27 pm

Re: Captive Portal - Redirect all IP to Single IP

Thu Dec 04, 2014 12:55 am

I can redirect web requests to my server - but not IP addresses (obviously)
take a look of this http://www.andybev.com/index.php/Using_ ... ive_portal
by the way.. how have you set the DNSMASQ to answer each request with the portal address??
thanks

LabhrasD
Posts: 1
Joined: Mon May 25, 2015 9:07 pm

Re: Captive Portal - Redirect all IP to Single IP

Mon May 25, 2015 9:19 pm

http://www.debuntu.org/how-to-redirecti ... -iptables/


This worked for me with the same Set up as above except I made some changes
First enable Forwarding

echo "1" > /proc/sys/net/ipv4/ip_forward


Then, we will add a rule telling to forward the traffic on port 80 to ip 192.168.42.1 on port 80 ( for example )

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

and finally, we ask IPtables to masquerade:

iptables -t nat -A POSTROUTING -j MASQUERADE

For me on my task that was it for now I have all http://( yourURLaddress ) :80 on the wifi access point going to http://192.168.42.1:80 which I have my index.html file seen as a welcome page , Android Tablet tested , although when you are signed in to Google on Chrome for example most traffic is HTTPS as you are searching through Google you are signed in to

I found this

http://superuser.com/questions/632181/r ... h-iptables

If anyone is interested to try let me know how this turned out for you

LabhrasD

Return to “Raspbian”

Who is online

Users browsing this forum: gkreidl, Google [Bot], neilld, Paul Webster and 26 guests