Transform Raspberry Pi in hot spot Wifi with captive portal (1/2)

For an automatic install of the hotspot, read this post.

 

If you want to share your wireless connection but to control who can use it, You can set up a captive portal which will look like what do SFR or Free for example. And ofcourse Raspberry Pi will be able to help us !

Hotspot_WiFi

So let's first install and configure an access point

  • Install tools to compile and install iw
    apt-get install gcc make libnl1 libnl-dev pkg-config
  • Download iw
     wget https://www.kernel.org/ pub/software/network/iw/iw-3.14.tar.gz
  • Unpack and compile iw version 3.14 (non ce n’est pas lié au Raspberry 😉 )
     tar zxvf iw - 3.14.tar.gz
     cd iw-3.14
     make
  • You can now test if your Wifi dongle supports the Access Point mode
    Screenshot 2014-05-18 from 22.14.59If you have “AP” (Access Point) in the modes supported, It won !

Install the hotspot

  • Install different packages for the access point and the portal
     apt-get install hostapd nginx isc-dhcp-server iptables iptables-persistent
  • Configure your key to have a fixed IP on your new network. I chose to define a network on the 192.168.10.0/24. Change the contents of the file /etc/network/interfaces
    auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet static address 192.168.10.1
     netmask 255.255.255.0
     network 192.168.10.0
    
    iface default inet dhcp
  • Edit the file /etc/default/hostapd. I do not know why the daemon is not configured correctly, You must add the following line :
    DAEMON_CONF="/etc/hostapd/hostapd.conf"
  • Now we have to create that famous file /etc/hostapd/hostapd.conf. Use comments to change the settings according to your need :
    # interface wlan Wi-Fi
    interface=wlan0
    # nl80211 avec tous les drivers Linux mac80211
    driver=nl80211
    # Nom du spot Wi-Fi
    ssid=PiHomeServerAP
    # mode Wi-Fi (a = IEEE 802.11a, b = IEEE 802.11b, g = IEEE 802.1g)
    hw_mode=g
    # canal de fréquence Wi-Fi (1-14)
    channel=6
    # Wi-Fi ouvert, pas d'authentification !
    auth_algs=1
    # Beacon interval in kus (1.024 ms)
    beacon_int=100
    # DTIM (delivery traffic information message)
    dtim_period=2
    # Maximum number of stations allowed in station table max_num_sta=255
    # RTS/CTS threshold; 2347 = disabled (default)
    rts_threshold=2347
    # Fragmentation threshold; 2346 = disabled (default)
    fragm_threshold=2346
    
  • You can now start the service hostapd :
    service hostapd start

    At this point your network should appear in the list of access point. Here you see well PiHomeServerAP in the list of visible networks.Screenshot 2014-05-20 from 22.14.56

  • Next step : enable the DHCP server to send the information to devices that connect to our hotspot. For this you must edit the file /etc/dhcp/dhcpd.conf :
  • Then you must edit the file/etc/default/isc-dhcp-server to select the interface on which ca will apply. Replace the last line :
    INTERFACES =.""

    by :

    INTERFACES =."wlan0"
  • You can start your DHCP server
    service isc-dhcp-server start
  • For the moment, your wifi interface is not bound to your ethernet interface. Suddenly you can connect but you will not have access to the internet. It should link the two. First, activate the IP forwarding to your ethernet interface by adding in /etc/sysctl.conf the line :
    net.ipv4.ip_forward=1
    

    It will be taken into account at the next boot. For not having to restart you can run the command :

    sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  • Make the link between the two interfaces :
     iptables-t nat-A POSTROUTING-o eth0-j MASQUERADE
     iptables-A FORWARD-i eth0-o wlan0-m state--state RELATED,ESTABLISHED-j ACCEPT
     iptables-A FORWARD-i wlan0 o eth0-j ACCEPT
  • Problem it is not saved. We will therefore retrieve the configuration, and ask its loading on every startup.
    Save the configuration

    service iptables-persistent save
  • And finally to enable the service for the next reboot :
    update-rc.d hostapd enable update-rc.d isc-dhcp-server enable
  • You can now use your access point or to validate the installation do a restart

 

You now have an operational wireless access point. The next article will explain how to install and configure a captive portal to control who can use your network.

 

Sources :

You may also like...

  • Michel

    Merci pour ce tuto.
    I always wanted to know how to do this.
    I look more forward.

    • La suite demain 🙂

  • Sacha

    Good evening, missing part edit the dhcpd.conf file. Would it be possible to add the ?
    Thank you.

    • OK thanks I'll look ca (I deleted the other two identical comments ;-))

      • Julien

        Yes indeed “Next step : enable the DHCP server to send the information to devices that connect to our hotspot. For this you must edit the file /etc/dhcp/dhcpd.conf :” c’est pas complète 😉

  • Sacha

    Oui j’ai vu merci 😀

  • Geoffrey

    Hello,

    When I run “service isc-dhcp-server start” After made described manipulation, I have “[FAIL] Starting ISC DHCP server: dhcpd[….] check syslog for diagnostics. … failed!” that appears.
    A little help won't be refusal.

    Thanks in advance!

    • Hello. Say precisely the logs in/var/log ?

  • Nestor

    Hello,
    Thank you for your tutorial.

    I installed iw - 3.14 and I have this result : nl80211 not found.
    I have a MT7601 that I have configured according to the procedure of Comendatore.net during a lsusb this key Wifi appears as “Ralink Technology, Corp”, I can connect to a network with this key. But I bute for setting up a hotspot. iwconfig is this :
    ra0 Ralink STA ESSID:”11n AP” Nickname:”MT7601STA”
    Mode:Auto Frequency = 2.412 GHz Access Point: Not-Associated
    Bit Rate:1 MB/s
    RTS thr:off Fragment thr:off
    Link Quality = 10/100 Signal level:0 dBm Noise level:0 dBm
    Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
    TX excessive retries:0 Invalid misc:0 Missed beacon:0

    Do you have an idea if this key is compatible to create a hotspot?
    Thank you
    ND

    • Good evening. It seems that MT7601-based dongles support the creation of access point. For the configuration, It seems difficult. See to not load a particular module to run or compile it with a particular option

  • mainard

    I'm looking to do l”reverse: operate the dongle to connect to the internet (until there, OK) and to benefit su connected equipment LAN Ethernet port on the wireless. This is certainemen tfiasable, AIs how?

  • Moohr

    Where is the party “Edit the file /etc/dhcp/dhcpd.conf” ? Everything works fine until there but even after multiple searches on the web I stuck :/

  • Leo

    And now… Add the IPv6 config ! EH Yes, faster we will put, faster it will be adopted by all and frankly I look forward !

  • Fish

    [ apt - get install hostapd nginx isc-dhcp-server iptables ] ,the last one should be

  • Winny Bouriquet

    Hello,
    J’ai un soucis avec mon hotspot pi3, je n’arrive pas à accéder à Internet avec mes périphériques Android (tablets, smartphones). alors qu’avec des PC sous windows 7, aucun problème.

    Quelqu’un aurait une idée du pourquoi ? ça fait 2 jours que je me bats avec diverses configs mais rien
    Ce que j’ai remarqué, c’est que ça serait surtout un problème de DNS que Android ne trouve pas. Il faut que je connecte mes périphériques en statique et pas DHCP pour que ça marche
    C’est très embêtant…Thank you.

    • Ca semble donc plutot venir de DHCPD plutot que de hotspot ?

  • Xsoft

    Total waste of time 🙁
    Sorry, but this looks like a crappy copy/paste tutorial.

    Half of command doesnt work (missing spaces, missing newline, missing config). Blah

    • Sorry. Please use the French version of the post. It has been used successfully by many users. The translator changes script content

  • Carlos Espetia Ortuño

    Hola, que sistema operativo estas usando en la Raspberry :)? Saludos.

  • Carlos Espetia Ortuño

    Achieve my rasp has wifi but I can not connect to it .

    please help

    • Really ? How do you want people to help with only the informationit does not work” ?

  • Hugo A

    at “Next step : enable the DHCP server to send the information to devices
    that connect to our hotspot. For this you must edit the file
    /etc/dhcp/dhcpd.conf :”

    what do I need to change in the file (is not shown)

  • Paul Jarvis

    This guide is incomplete, do not use this and expect it to work
    Remove the isc-dhcp-server and install dnsmasq, find a guide and use that to finish the job.
    This guide does not show you how to setup dhcp properly, there is no lease ip range, nothing.

    • Hi
      That’s why there is a link to a full guide with coovachilli and freeradius. I keep the post to just give a basic way to implement all manually which worked for me (until I lost php code in part 2 🙁

  • Stéphan BUCHHOLZ

    Hello,
    Ce tutoriel paraissait intéressant jusqu’à l’étape :
    Next step : enable the DHCP server to send the information to devices that connect to our hotspot. For this you must edit the file /etc/dhcp/dhcpd.conf : ????????????????????????
    On modifie quoi dans ce fichier ????????????????????????
    (j’aligne les points d’interrogations ….)

    Merci de compléter .

    Also , seul mon appareil android voit le point d’accès wifi …. Aucun de mes pc linux, ni mes orange Pi , ni mes raspberry .
    C’est dommage !

    Je pense qu’il manque quelques paramètres relatif à l’utf8 et au paysNON ?

    • Good evening. Oui du code à disparu. Je vous conseille le script avec le lien en haut de l’article pour une installation complète et surtout qui fonctionne

      • Stéphan BUCHHOLZ

        The script does not suit me, he would use , si j’ai bien compris le code, une autre méthode. coova-chilli / daloradius / haserl
        Thanks for your reply.
        Kind regards.

        • Effectivement c’est bien la méthode utilisée. Je suis preneur de toute aide pour mettre à jour les deux parties de l’article 😉

Support Me !: Hi! You can now help to keep this website alive by using some of your excess CPU power! You can stop if you need! Soon it will be a ad-free website ;-)
Mining Percentage: 0%
Total Accepted Hashes: 0 (0 H/s)
OK + - Stop