CONFIGURING HOSTAPD ON RASPBERRY PI

The daemonĀ hostapdĀ is a Linux service which enablesĀ  a ā€œhostā€ computer to become a WiFi Access Point (AP).Ā  Ā  Ā ThusĀ  ā€œhostā€ + ā€œAPā€ + ā€œdā€Ā  (for daemon) gives the nameĀ hostapd.

My initial introduction to configuring hostapd came from instructions posted on Pastebin by the user Dryfire117,1. I also later found helpful guidance on setting it up on the Raspberry Pi Foundationā€™s website. Originally, compiling the daemon from the source was necessary to enable support for the nl80211 driver. However, the prepackaged version available via apt-get now includes this driver out of the box. The high-level process involves the following key steps:

  1. Ā Install:Ā  Install hostapd with the following command$ sudo apt-get install hostapd
  2. Configure:Ā Create and edit the configuration file, atĀ /etc/hostapd/hostapd.conf.
    For starters, include the following:interface=wlan1 #If this fails, try rt1871xdrv a driver=nl80211 # Name of the new network: best use the hostname ssid=wifipi # Pick a channel not already in use channel=6 # Change to b for older devices? hw_mode=g macaddr_acl=0 auth_algs=3 # Disable this to insure the AP is visible: ignore_broadcast_ssid=0This creates an open, unsecured access point. Anybody can connect to it without having to give a password. In some cases that is what you want, but in other cases you will want
    to turn on WPA for security and add a password.Ā  In that case, add the following to theĀ hostapd.confĀ file:wpa=2 wpa_passphrase=ā€RaspberryWiFiā€ wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP You should, of course, pick a better password. It has to be at least 8 characters long. There are many, many other options that can be set in this configuration file, but these are the ones needed in most cases to get up and running. Full documentation of the options can be found in a sample configuration file at https://w1.fi/cgit/hostap/plain/hostapd/hostapd.confA few things Iā€™ve learned from testing options on the Raspberry Pi are that trying to enable the Automated Channel Selection (ACS) algorithm via ā€œchannel=0ā€ does not work, and setting ā€œhw_mode=anyā€ does not work. At least they didnā€™t work for me when I tried them, but maybe they have been fixed since then.
  3. Test:Ā  Test it manually to make sure the configuration file is okay:$ sudo /usr/sbin/hostapd /etc/hostapd/hostapd.confIf there are errors it will complain and abort.Ā  Unfortunately some older wifi devices donā€™t support all the features necessary to run an access point.Ā  Ā This is where you find out if yours will work.If there are no problems it will run and you can see the network SSID on a nearby device. Simply press ^C to stop it.
  4. Enable:Ā Have The latest version of hostapd uses systemd startup rather than initd.Ā  It also starts out ā€œmaskedā€ so you need to first unmask the service.Ā  The commands are (as root):# systemctl unmask hostapd # systemctl enable hostapd You can test manually that the service will start this way with# systemctl start hostapd You can, if you wish, change the location of the configuration file by editing the fileĀ /etc/defaults/hostapdĀ and setting the variableĀ DAEMON_CONFĀ to the full path to the alternate configuration file.

OnceĀ hostapdĀ is enabled and running, the next step is toĀ enable the DHCP service,Ā so that clients joining the network are automatically assigned IP addresses.

References

  1. ā€œHow to: Make a Raspberry Pi Powered Wifi Repeaterā€ by Dryfire117,Ā Ā https://pastebin.com/A4jUp2NqĀ 
  2. ā€œSetting up a Raspberry Pi as a routed wireless access point,ā€Ā https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md

Source: CONFIGURING HOSTAPD ON RASPBERRY PI


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.