![]() |
| Edimax USB WiFi adapter |
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
# Static IP assignment connecting
# to access point with hidden ssid
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.100.43
netmask 255.255.255.0
gateway 192.168.100.1
wpa-ap-scan 1
wpa-scan-ssid 1
wpa-ssid "THESSIDHERE"
wpa-proto RSN
wpa-pairwise CCMP
wpa-key-mgmt WPA-PSK
wpa-psk "THEWIRELESSPASSWORDHERE"
All this is very nice and practical but for a project that I'll be elaborating on in a future post, I envisioned the need to be able to connect (via ssh, http, etc) to the RPi via wifi directly without having the need for a separate wireless router. The obvious straight forward approach is to set up the wireless adapter to use AdHoc mode. This was not as elegant as I'd like.
Instead, I wanted the RPi to act as a wireless hotspot or more simply a wifi access point with a broadcasting ssid, password, and a built in dhcp server to issue IP addresses to guests connecting. I found this page (http://raspberrypihq.com/how-to-turn-a-raspberry-pi-into-a-wifi-router) detailing how you can use HostAPD and isc-dhcp-server to turn the RPi into a wireless router. For what I wanted, that would be a good solution but since all I wanted was a simple AP, I could skip the routing and NATing parts of the setup. You can read that page for more info but I modified the steps slightly here to show what I did to get it to work. There were some errors with those instructions so I decided to write up all my steps even though there's some duplication. I'm assuming the wifi adapter is detected at this point and the RPi currently has an Internet connection (via the Ethernet port) in order to download and install the requisite software.
Install the DHCP server:
sudo apt-get install isc-dhcp-server
Install the custom version of HostAPD that includes modified network drivers. During compilation, I did see several warnings but it was mostly about unused variables so they can all be safely ignored.
git clone https://github.com/jenssegers/RTL8188-hostapd.git
cd RTL8818-hostapd/hostapd
sudo make
sudo make install
Now we have to prep dhcpd with the subnet and range of IPs to issue. We need to edit /etc/dhcp/dhcpd.conf for that. As mentioned in the referenced doc, comment out these options
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
and uncomment the "authoritative;" line to make it authoritative# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
Add this snippet to the end of the file to configure the dhcp server to issue up to 90 IP addresses in the 192.168.200.0/24 space. Admittedly this is overkill and reducing this to 10 IPs is probably sufficient in which case just change 192.168.200.100 to 192.168.200.20. subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.10 192.168.200.100;
option broadcast-address 192.168.200.255;
option routers 192.168.200.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "rpi-local";
}
You can see the complete dhcpd.conf file here for reference.Next we have to configure the DHCP server to only respond to requests through the wifi adapter since we don't want it acting as a DHCP server over the wired connection. We do this by editing /etc/default/isc-dhcp-server and changing the INTERFACES line to wlan0
INTERFACES="wlan0"
We then have to assign a static IP to the wifi adapter. We'll use the first IP address of the subnet we're assigning to this interface so with the current configuration we're going to use 192.168.200.1. The address we choose in the 192.168.200.0/24 range isn't really important as long as its not in the range we configured for the dhcp server to issue.
Edit /etc/network/interfaces to look like the configuration below. The import part is the static configuration for wlan0 and optionally commenting out wlan1 if you don't plan on having a second wifi adapter plugged in at the same time.
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.200.1
netmask 255.255.255.0
#allow-hotplug wlan1
#iface wlan1 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Next we have to configure HostAPD with the ssid and wifi password we want to advertise and the password to secure it with. To do this, edit /etc/hostapd/hostapd.conf and change the values for ssid and wpa_passphrase. In my case I used rpilocal as the ssid with a complex passphrase.
Now cycle the wlan0 interface so it picks up the new settings
sudo ifdown wlan0
sudo ifup wlan0
Enable the hostapd and isc-dhcp-server services to run at their configured runlevels
sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable
Start the services to make sure they start up with no errors. If you didn't enable the services in the step above, I found that the hostapd service throws a file not found error when trying to start it. This sequence was reversed in the page I was referencing so make sure you enable it before trying to start the services.
sudo service isc-dhcp-server start
sudo service hostapd start
If all is well then you should be able to see the SSID advertised and be able to connect to it using any wifi client like your laptop, tablet or phone with the password you set. Once connected, you should then be able to ping 192.168.200.1 from the client and connect to the RPi using any means you'd like such as ssh.
![]() |
| RPi Access Point now visible to my iPhone |
Known Issues:
I've observed that on occasion, especially from a cold boot, the RPi can hang when at the login prompt after boot if the wifi adapter is plugged in. I'm still trying to figure out if this is a hardware of software issue but the workaround is:
- Boot the RPi without the wifi adapter
- Once logged in, plug in the wifi adapter
- In a terminal, run ifconfig to make sure that wlan0 is up
- Restart isc-dhcp-server
sudo service isc-dhcp-server restart - Restart hostapd
sudo service hostapd restart


No comments:
Post a Comment