Skip to content

Instantly share code, notes, and snippets.

Last active June 23, 2024 20:04
Show Gist options
  • Save ExtremeGTX/ea1d1c12dde8261b263ab2fead983dc8 to your computer and use it in GitHub Desktop.
Save ExtremeGTX/ea1d1c12dde8261b263ab2fead983dc8 to your computer and use it in GitHub Desktop.
Setup Ubuntu server as Access point


This tutorial for setting up Ubuntu Server (RPi 3B) as Wifi access point


The main steps can be listed as following:

  1. Install required packages
  2. Setup hostapd
  3. Setup DNSmasq
  4. Configure AP IP Address

Install required packages

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

  • 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 #

  • 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/

  • Create a new config file by: sudo vi /etc/dnsmasq.conf

  • This config file will automatically assign addresses between and with lease time 24 hours.

  • Then Let's reload dnsmasq config

    sudo systemctl reload dnsmasq

Solving startup Error:

  • 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= and Wants= under [Unit] section.

    sudo vi /lib/systemd/system/dnsmasq.service


Config static IP

  • Ubuntu uses cloud-init for initial setup, so will modify the following file to set wlan0 IP.


  • Modify the cloud-init file by sudo vi /etc/netplan/50-cloud-init.yaml

  • Add the following content to the file:

                dhcp4: false
  • 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}
        version: 2
                dhcp4: true
                    macaddress: 12:34:56:78:ab:cd
                set-name: eth0
                dhcp4: false


  • 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 by sudo 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 by sudo systemctl status dnsmasq.

Copy link

Thanks for share! Nice job.

Just to add something, following your directions, I was stuck on an error when starting dnsmasq:
failed to create listening socket for port 53: Address already in use

This error occurs because systemd-resolved is running and use this port. Particularly, I don't want to change this behavior and just disabled dnsmasq DNS feature, so I simply changed the port adding to file /etc/dnsmasq.conf:

Just in case someone else needs if found this tutorial.

Copy link

yaniron commented Jan 2, 2021

if you want dnsmasq to be your resolver, you can also follow the instructions here:

Copy link

dony71 commented Jan 13, 2021

I have ubuntu 20.04 and I don't know why keep getting "unknown interface wlan0"
Anything I'm missing?

cat /lib/systemd/system/dnsmasq.service

Description=dnsmasq - A lightweight DHCP and caching DNS server


ExecStartPre=/usr/sbin/dnsmasq --test

ExecStart=/etc/init.d/dnsmasq systemd-exec

ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf
ExecStop=/etc/init.d/dnsmasq systemd-stop-resolvconf

ExecReload=/bin/kill -HUP $MAINPID


Copy link

Hi dony71,

wlan0 is the device name of the wireless card. The example was assuming Raspberry Pi hardware, and that should be the name of the built in wireless on a Raspberry by 3/4. The instructions have you edit a .yaml file in the /etc/netplan directory, and the device name is specified in that file.

If you are getting and unknown interface wlan0, it is most likely because your wireless card has a different name, and you would have to put it's correct name in the .yaml file.

To find the name of your wireless card device, you could do this:

sudo lshw -c network

In the output of that command you should look for "Wireless" in the description, and in that section, the logical name will be the device name you need. Unfortunately not all wireless card all supported, and it is still possible that lshw will not have a logical name for your device.

Hope that helps.

Copy link

Baerlie commented Mar 31, 2021

Thank you for this short and easy setup procedure! I had the same problem as rfloriano with port 53. I changed the conf as advised and it's working. Thank you!

Copy link

Robotgir commented Jun 2, 2021

Can any one kindly guide me?
how can i ssh into the rpi which is configured as access point?
What will be the ip address of the access point?

Copy link

Following this guide, I can see the ssid from my phone, but attempting to connect invariably leads to an invalid password error. The iPhone error reads "Incorrect password for <>". Obviously my password is over 8 characters long, correctly typed. Any idea what can be wrong?

Copy link

I noticed that, in some cases systemd-resolved service and dnsmasq service can conflict with each other. This answer would help in those scenarios.

Copy link

grkidwell commented Dec 11, 2021

am successfully getting an ip address from the pi and can ssh into the pi, but cannot access the internet from a client using the pi as an access point. pings to or any other ip address do not return. I am a bit confused in how ip forwarding is handled with this overall procedure, as in the past when creating an accesspoint on raspiOS, ip forwarding had to be enabled and iptables edited.

Copy link

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment