Setting up Raspberry Pi as Wi-Fi Access Point using Hostapd
In this article, we will cover the steps required to configure a Raspberry Pi as a Wi-Fi access point, allowing mobile devices to connect to it and obtain an IP address, including DNS settings. By following these steps, you will be able to create a portable wireless network using your Raspberry Pi.
What is a Wi-Fi Access Point?
A Wi-Fi access point (AP) is a network device that allows wireless devices to connect to a wired network using Wi-Fi or Wireless Fidelity. The access point can be a standalone device that is connected to a router or it can be a component of a router itself. In our case, we will be converting a Raspberry Pi into a Wi-Fi access point.
What is Hostapd?
Hostapd is a user space daemon that allows you to turn your wireless card into an access point. It supports various wireless cards and drivers, making it a popular choice for setting up access points on Linux-based systems.
Prerequisites
Before we begin, make sure you have the following:
- A Raspberry Pi with a wireless network card
- A USB keyboard and HDMI monitor (for initial setup)
- A valid IP address for your Raspberry Pi on your network
Setting up the Access Point
We will be configuring the Raspberry Pi as an access point, allowing mobile devices to connect to it. To achieve this, we will install and configure Hostapd and create a new network interface.
# Update your system
sudo apt-get update
# Install Hostapd and bridge-utils
sudo apt-get install hostapd bridge-utils
# Stop the servicess
sudo systemctl stop networking
sudo systemctl stop dhcpcd
# Create a new network interface
sudo nano /etc/network/interfaces.d/wlan0
Add the following content to the newly created file:
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Now, we need to configure Hostapd. Create a new configuration file:
sudo nano /etc/hostapd/hostapd.conf
Add the following content to the new file:
interface=wlan0
driver=nl80211
ssid=MyAccessPoint
hw_mode=g
channel=6
wpa=2
wpa_passphrase=MySecretPassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Replace "MyAccessPoint" and "MySecretPassphrase" with your desired SSID and passphrase. This will create a basic WPA2 secured network.
Configuring DHCP Server
To assign IP addresses to connecting devices, we need to configure a DHCP server. Install the isc-dhcp-server package:
sudo apt-get install isc-dhcp-server
Open the DHCP server configuration file:
sudo nano /etc/dhcp/dhcpd.conf
Add the following content to the file:
ddns-update-style none;
option domain-name "local";
option domain-name-servers 192.168.4.1;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
subnet 192.168.4.0 netmask 255.255.255.0 {
range 192.168.4.10 192.168.4.50;
option routers 192.168.4.1;
}
This will configure the DHCP server to assign IP addresses in the 192.168.4.0/24 range, with a default gateway of 192.168.4.1 (the Raspberry Pi).
Starting the Services
To start the services, enable them to start on boot and then start them:
sudo systemctl unmask hostapd.service
sudo systemctl enable hostapd.service
sudo systemctl start hostapd.service
sudo systemctl unmask isc-dhcp-server.service
sudo systemctl enable isc-dhcp-server.service
sudo systemctl start isc-dhcp-server.service
sudo systemctl start networking
sudo systemctl start dhcpcd
In this article, we have learned how to configure a Raspberry Pi as a Wi-Fi access point using Hostapd. We have also covered creating a new network interface and configuring a DHCP server to assign IP addresses to connecting devices. With these steps completed, you should now have a functional wireless network using your Raspberry Pi.