This tutorial for setting up Ubuntu Server (RPi 3B) as Wifi access point
The main steps can be listed as following:
- Install required packages
- Setup hostapd
- Setup DNSmasq
- Configure AP IP Address
sudo apt-get install hostapd dnsmasq
-
The purpose of Hostapd is to set WiFi as an access point
-
we need to write a new config file for hostapd
sudo vi /etc/hostapd/hostapd.conf
interface=wlan0 driver=nl80211 ssid=MyWiFiNetwork hw_mode=g channel=7 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=12345678 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
-
Then we need to tell hostapd to use our config file, edit
/etc/default/hostapd
and change the line starts with#DAEMON_CONF
, remember to remove#
DAEMON_CONF="/etc/hostapd/hostapd.conf"
-
Then Let's start hostapd
sudo systemctl unmask hostapd sudo systemctl enable hostapd sudo systemctl start hostapd
-
The purpose of dnsmasq is to act as DHCP Server, so when a devies connects to Raspberry Pi it can get an IP assigned to it.
-
make a backup of default config by:
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.org
-
Create a new config file by:
sudo vi /etc/dnsmasq.conf
-
This config file will automatically assign addresses between
192.168.4.2
and192.168.4.20
with lease time24
hours.interface=wlan0 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
-
Then Let's reload dnsmasq config
sudo systemctl reload dnsmasq
-
On System startup, dnsmasq will not wait for wlan0 interface to initialize and will fail with error
wlan0 not found
. -
We need to tell systemd to launch it after network get ready, so we will modify dnsmasq service file by adding
After=
andWants=
under[Unit]
section.sudo vi /lib/systemd/system/dnsmasq.service
[Unit] ... After=network-online.target Wants=network-online.target
-
Ubuntu uses cloud-init for initial setup, so will modify the following file to set wlan0 IP.
-
DON'T USE TABS IN THIS FILE, IT WILL NOT WORK, EVER!!
-
Modify the cloud-init file by
sudo vi /etc/netplan/50-cloud-init.yaml
-
Add the following content to the file:
wlan0: dhcp4: false addresses: - 192.168.4.1/24
-
The file will finally looks like this:
# This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: version: 2 ethernets: eth0: dhcp4: true match: macaddress: 12:34:56:78:ab:cd set-name: eth0 wlan0: dhcp4: false addresses: - 192.168.4.1/24
- Reboot your Raspberry Pi and check if you can connect to it over WiFi and can SSH.
-
if you can't see Raspberry Pi Hot spot then
hostapd
is not working, you can check its logs bysudo systemctl status hostapd
. -
if you can coonect to Raspberry Pi but can't get an IP then
dnsmasq
is not working, you can check its logs bysudo systemctl status dnsmasq
.
I was having issues with the DHCP server not allocating ip's. Seems like it was my firewall stopping it.
You can find the ufw rules here:
https://ubuntuforums.org/showthread.php?t=1146048