Using Linux as a wireless access point

Debian Linux Networking

A (very) quick ‘howto’ to make a wireless access point from a Linux machine (should also with with Raspberry Pi with some modifications to the config files)

NOTE: This howto assumes you already have a supported wireless network adaptor – not all adaptors support AP mode.

Requirements: ifupdown / bridge-utils/ crda / wireless-regdb / hostapd / aircrack-ng

Apt commands to remove / install the software as required.

apt purge nplan netplan.io
apt install ifupdown
apt install bridge-utils
apt install wireless-regdb
apt install crda
apt install hostapd
apt install aircrack-ng

My wireless adaptor is wlp2s0 – airmon-ng creates wlp2s0mon (you will need to change wlp2s0 for your adaptor, and airmon-ng will create an adaptor based on that name – you will need to adjust the info below accordingly)

Network configuration: (/etc/network/interfaces) – create the bridge br0 and assign the Ethernet and wireless interfaces to it.

allow-hotplug wlp2s0

auto br0
iface br0 inet static
        pre-up { brctl addbr br0 && brctl addif enp3s0 wlp2s0; } || true
        bridge_ports enp3s0
        address 192.168.1.1
        network 192.168.1.0
        netmask 255.255.255.0
        broadcast 192.168.1.255
        gateway 192.168.1.254

Create configs in /etc/default

/etc/default/airmong

# airmon options
ARG1='start'
ARG2='wlp2s0'

/etc/default/hostapd

ARG1='-i'
ARG2='wlp2s0mon'
ARG3='/etc/hostapd/hostapd-simple.conf'

hostapd config

/etc/hostapd/hostapd-simple.conf

#### Interface configuration ####
interface=wlp2s0mon
# interface=wlp2s0
bridge=br0
driver=nl80211
##### IEEE 802.11 related configuration #####
ssid=linux-ap
hw_mode=g
# hw_mode=n # unsupported (for me)
channel=4
wmm_enabled=1
country_code=GB
ieee80211d=1
ieee80211h=0
##### IEEE 802.11n related configuration #####
ieee80211n=1
##### WPA/IEEE 802.11i configuration #####
auth_algs=1 # wpa only
# wpa2 only
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_passphrase=[your passphrase]
macaddr_acl=0

Create systemd unit files in /etc/systemd/system
airmon.service

[Unit]
Description=Airmon service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
# Restart=
# RestartSec=1
EnvironmentFile=/etc/default/airmong
User=root
ExecStart=/usr/sbin/airmon-ng $ARG1 $ARG2

[Install]
WantedBy=multi-user.target

hostapd.service

[Unit]
Description=Hostapd service
After=sys-class-net-wlp2s0mon.device airmon.service
StartLimitIntervalSec=0

[Service]
Type=simple
EnvironmentFile=/etc/default/hostapd
User=root
ExecStartPre=/usr/bin/sleep 3
ExecStart=/usr/sbin/hostapd $ARG1 $ARG2 $ARG3

[Install]
WantedBy=multi-user.target

NOTE: Some of the sites below recommend installing dnsmasq – but I already have DHCP and DNS servers on my network so dnsmasq was not required in my case. As always, your use case might differ.

Sources:

https://stackoverflow.com/questions/70944393/hostapd-free-hapd-data-interface-wlan0-wasnt-started
https://forum.doozan.com/read.php?2,6300
https://www.shubhamdipt.com/blog/how-to-create-a-systemd-service-in-linux/
https://unix.stackexchange.com/questions/257888/systemd-wait-for-network-interface-to-be-up-before-running-service
https://pychao.com/2021/02/24/difference-between-partof-and-bindsto-in-a-systemd-unit/
https://stackoverflow.com/questions/43001223/how-to-ensure-that-there-is-a-delay-before-a-service-is-started-in-systemd
https://wiki.gentoo.org/wiki/Hostapd#802.11b.2Fg.2Fn_with_WPA2-PSK_and_CCMP
https://superuser.com/questions/728951/systemd-giving-my-service-multiple-arguments
https://askubuntu.com/questions/472794/hostapd-error-nl80211-could-not-configure-driver-mode
https://medium.com/@renaudcerrato/how-to-build-your-own-wireless-router-from-scratch-part-3-d54eecce157f