417. Access point
This page is for turning a KDOS machine’s wireless card into an access point: a Wi-Fi network that phones, laptops and other devices can join. There are two ways:
- The hotspot shares the machine’s own internet connection. You start it from the network applet, System Settings or
nmcli, and NetworkManager sets up everything it needs. This is the way most people want. - hostapd makes the machine itself the network: an access point that stays up across reboots, with or without an internet connection, configured by hand.
Installation
| Port | Provides |
|---|---|
| networkmanager, wpa_supplicant | The hotspot: ipv4.method = shared on an access-point profile |
| dnsmasq | The DHCP and DNS server, for the hotspot and for a hostapd network |
| nftables | The firewall, and the address translation NetworkManager installs for a hotspot |
| hostapd | hostapd and hostapd_cli |
| iw | iw, which shows what a card can do |
| plasma-nm | The network applet’s Hotspot button, and the hotspot’s name and passphrase in System Settings → Wi-Fi & Networking |
All but hostapd are in the base the ISO carries; sudo kdos update install hostapd adds it (see Installing software). Its service script, /etc/init.d/46_hostapd.sh, is part of the base filesystem and enabled, and starts nothing while the program is missing ([SKIP] hostapd: /usr/sbin/hostapd not found) or until /etc/hostapd/hostapd.conf exists: at boot it then writes [SKIP] hostapd: no /etc/hostapd/hostapd.conf to /run/kdos-init.hostapd.log, and service status hostapd reports [DOWN] hostapd. The hotspot needs no service of its own beyond NetworkManager.
Before either, check that the card can be an access point:
iw list
Under Supported interface modes, the list must include * AP. iw list prints nothing on a machine with no wireless card, and nmcli device wifi hotspot there answers Error: No Wi-Fi device found. The network applet offers its Hotspot button only for a radio that reports the capability.
Configuration
The firewall’s hotspot rules
The shipped firewall drops incoming and forwarded traffic by default. These lines of /etc/nftables.conf, from fs/, let a hotspot’s clients get an address and a resolver:
# A HOTSPOT'S CLIENTS NEED A LEASE AND A RESOLVER, and this is
# the only place they can be let in. Plasma's Wi-Fi hotspot is
# NetworkManager's `ipv4.method = shared`, which starts dnsmasq
# on the access point's own interface; NetworkManager's shared
# table deliberately carries NO input chain, so with the policy
# above a client associates, ARPs, answers a ping and never
# gets an address.
#
# SCOPED TO THE SUBNET NetworkManager HANDS OUT, not to an
# interface name this file cannot know: 10.42.0.0/16 is the
# pool it allocates a /24 out of for every shared connection.
# Off that subnet these two ports stay closed.
ip saddr 10.42.0.0/16 udp dport { 53, 67 } accept
ip saddr 10.42.0.0/16 tcp dport 53 accept
fs/etc/nftables.conf, lines 105–118
and let their traffic through the machine:
# EXCEPT A HOTSPOT, AND THE POLICY ABOVE IS WHY THIS HAS TO BE
# HERE. NetworkManager registers its own forward chain on this
# same hook with policy accept when a shared connection comes
# up — but in netfilter an `accept` verdict ends only the chain
# that issued it: the packet still meets every other base chain
# on the hook, and a drop anywhere is final. So NetworkManager's
# chain cannot rescue a packet this one drops, in either
# registration order, and a hotspot would associate, lease an
# address and route nothing.
#
# The subnet is NetworkManager's own shared pool, so this opens
# forwarding for a hotspot and for nothing else.
ct state established,related accept
ip saddr 10.42.0.0/16 accept
ip daddr 10.42.0.0/16 accept
fs/etc/nftables.conf, lines 132–146
Both are scoped to 10.42.0.0/16, the range NetworkManager gives shared connections. A network of your own made with hostapd gets none of this; see Serving a network with hostapd. How the file is loaded and why NetworkManager’s own tables survive a reload is in /etc/nftables.conf.
The hotspot profile
The network applet creates a profile named Hotspot, with the name and passphrase set under System Settings → Wi-Fi & Networking → Wi-Fi Hotspot, and autoconnect off, so a hotspot never takes the radio at the next boot. The passphrase must be eight characters or more. nmcli device wifi hotspot creates a profile named Hotspot as well, also with autoconnect off. Both are kept in /etc/NetworkManager/system-connections/.
NetworkManager starts a separate dnsmasq for each shared connection. It reads any files in /etc/NetworkManager/dnsmasq-shared.d/, and keeps its leases in /var/lib/NetworkManager/dnsmasq-<interface>.leases.
hostapd
. /etc/init.d/service_helper
# A WIRELESS ACCESS POINT, AND ONLY WHEN SOMEBODY WROTE ONE. The package ships
# hostapd.conf.example and no hostapd.conf, so a machine nobody configured
# skips here rather than supervising a daemon that exits on a missing file.
#
# NetworkManager must be told to leave the interface alone —
# `unmanaged-devices=interface-name:<if>` in /etc/NetworkManager/conf.d —
# or it and hostapd both drive the same card. Addresses and names for the
# clients are a dnsmasq of the administrator's own, which needs
# `bind-interfaces` beside NetworkManager's loopback one, and the firewall does not
# let a hand-made subnet in: see docs/kdos/02-user-guide/administration.md.
# Plasma's Wi-Fi hotspot is the other way to an access point and needs none of it.
NAME="hostapd"
DAEMON="/usr/sbin/hostapd"
CONF="/etc/hostapd/hostapd.conf"
case "$1" in
start)
if [ ! -x "$DAEMON" ]; then
echo "[SKIP] $NAME: $DAEMON not found"
exit 0
fi
if [ ! -f "$CONF" ]; then
echo "[SKIP] $NAME: no $CONF"
exit 0
fi
echo "[KDOS] Starting $NAME..."
# Foreground for supervision (no -B); -s logs to syslog, as there is
# no terminal to log to.
supervise "$NAME" "$DAEMON" -s "$CONF"
;;
stop)
stop_service "$NAME"
;;
status)
check_status "$NAME"
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
The service script starts hostapd only when /etc/hostapd/hostapd.conf exists, and runs it in the foreground with -s, so it logs to the system log. The package installs upstream’s annotated example beside that path, from its build.sh:
install -Dm755 hostapd $PKG/usr/sbin/hostapd
install -Dm755 hostapd_cli $PKG/usr/bin/hostapd_cli
install -Dm644 hostapd.conf $PKG/etc/hostapd/hostapd.conf.example
install -Dm644 hostapd.8 $PKG/usr/share/man/man8/hostapd.8
install -Dm644 hostapd_cli.1 $PKG/usr/share/man/man1/hostapd_cli.1
ports/core/network/hostapd/build.sh, lines 64–68
Every key is described in /etc/hostapd/hostapd.conf.example itself; hostapd(8) and hostapd_cli(1) cover the two commands.
Usage
Sharing the connection from the desktop
- Set the hotspot’s name and a passphrase of at least eight characters once, on System Settings → Wi-Fi & Networking → Wi-Fi Hotspot.
- Click the network applet in the tray, then Hotspot. The applet shows the network’s name and passphrase while it runs.
- On the other device, join that network with that passphrase.
- Click Hotspot again to stop. The radio then goes back to the saved network it is normally on.
Sharing the connection from a terminal
Start a hotspot with a name and a passphrase of your choice:
nmcli device wifi hotspot ifname <interface> ssid <name> password <passphrase>ifnameis a wireless interface fromiw dev;nmcli device wifi hotspotalso takesbandandchannel.Stop it:
nmcli connection down HotspotStop it this way rather than with
nmcli device disconnect, which also keeps the radio from rejoining its usual network on its own.
A member of wheel logged in at the machine needs neither sudo nor a password for either command: NetworkManager’s own polkit policy allows sharing a connection to the active local session, and KDOS’s rule lets wheel save the Hotspot profile, which every user shares. Anyone else is asked for an administrator’s password (see NetworkManager).
Serving a network with hostapd
This is the long way, for a machine that is the network. The procedure follows An access point with hostapd.
Write the access point’s configuration, starting from the example:
sudo cp /etc/hostapd/hostapd.conf.example /etc/hostapd/hostapd.conf sudoedit /etc/hostapd/hostapd.confSet at least
interface,ssid,hw_modeandchannel, and thewpaandwpa_passphrasekeys for a protected network. Setcountry_codeto the country the machine is in; see Wireless regulatory domain.Tell NetworkManager to leave the card alone, or both drive it at once. Create
/etc/NetworkManager/conf.d/50-hostapd.confholding:[keyfile] unmanaged-devices=interface-name:<interface>then restart NetworkManager with
sudo service restart networkmanager(Restarting the daemon).NetworkManager --print-configshows the[keyfile]line, andnmcli device statuslists the card asunmanaged. NetworkManager leaves an address and a route the card already had in place;sudo ip addr flush dev <interface>removes them.Give the interface an address, and run a
dnsmasqof your own on it for DHCP and DNS, from an init script of your own in/etc/init.d(Writing a service).46_hostapd.shis a model for one. Itsdnsmasqneedsinterface=<interface>,bind-interfacesand adhcp-range=line, and--keep-in-foregroundon the command line so the supervisor watches it. Withoutbind-interfacesit collides with NetworkManager’s resolver on port 53 and serves no clients.Let the clients through the firewall: a file of your own in
/etc/nftables.d, with a name ending in.nft(the only files/etc/nftables.confincludes), acceptingudp dport { 53, 67 }andtcp dport 53withiifname "<interface>"in theinputchain, and, if they should reach anything beyond this machine, accepting forwarding from that interface. See Adding a rule of your own for the file’s shape and how to load it.Start it, or reboot:
sudo service start hostapd
KDOS ships no example of the address, the dnsmasq script or the firewall file for this route, and no procedure for routing the clients’ traffic to an uplink.
On the live medium and on an installed system
Both ways are available on the live medium. A hostapd network made there lasts until the next reboot unless the medium has a persistence store; on an installed system 46_hostapd starts it at every boot.
Tips
sudo hostapd_cli all_stalists the clients associated with ahostapdaccess point. It talks tohostapdthrough thectrl_interfacethe example configuration sets, so keep that line.- A hotspot’s clients and their addresses are in its lease file,
/var/lib/NetworkManager/dnsmasq-<interface>.leases, which root may read. sudo nft list tablesshows anm-shared-<interface>table while a hotspot is up: that is the address translation NetworkManager installed. A change made withkdos-firewallleaves it in place. Without a hotspot the firewall’s own table isinet filter; any other table in the list belongs to another program, such as libvirt while one of its virtual networks runs.
Troubleshooting
The network applet offers no Hotspot button. No wireless device reported the access-point capability. iw list shows whether the card lists AP among its interface modes; if it does not, the card or its driver cannot serve.
A client joins and never gets an address. The firewall dropped its DHCP request. For a hotspot, sudo nft list ruleset | grep 10.42 should show the shipped lines above. They are missing only when /etc/nftables.conf did not load at boot even without /etc/nftables.d, and the boot fell back to its minimal policy. For hostapd, check that your own .nft file in /etc/nftables.d is in sudo nft list ruleset and that your dnsmasq is running. In both cases /run/kdos-init.nftables.log holds the firewall’s boot output.
A client has an address and reaches nothing beyond this machine. For a hotspot, check that the machine itself is online and that nm-shared-<interface> is among sudo nft list tables. For hostapd, forwarding and address translation are yours to add.
hostapd keeps restarting. It exits on an error in its configuration and the supervisor starts it again five seconds later. sudo grep hostapd /var/log/messages shows the line it refused. Running it once in the foreground with debugging, sudo hostapd -d /etc/hostapd/hostapd.conf, after sudo service stop hostapd, prints the same reason on the terminal.
hostapd reports that the interface is busy or cannot be put in AP mode. NetworkManager still manages the card. nmcli device status must list it as unmanaged; see step 2 of Serving a network with hostapd.
5 GHz channels are refused. The radio is still in the world regulatory domain, where channels that need radar detection are closed. See Wireless regulatory domain.
Known gaps
No access point has yet been started on real hardware running KDOS. The hotspot, hostapd and the lease files are described from KDOS’s configuration and the upstream programs. What has been checked, in a virtual machine with no wireless card, is the answer each tool gives when there is no card, the shipped firewall lines, the service script’s skip and the unmanaged-devices setting. If something here does not match what your machine does, the Troubleshooting steps still apply.
The KDOS book lists no gap specific to access points. The one that bears on them is kdos doctor cannot check hardware a machine does not have.
See also
- An access point with hostapd
- Firewall: the named services the access point needs open
- The firewall
- NetworkManager, DNS, Wireless regulatory domain
- Firewall, Writing a service