Using 802.11 (WiFi) under NetBSD

Wireless networking under NetBSD


Wireless networking under NetBSD

This document describes how to configure and troubleshoot IEEE 802.11 networking under NetBSD.

NetBSD supports a number of PCI/USB/PCMCIA/Cardbus based IEEE 802.11 compatible network cards. As of 2021, the most commonly available devices include Realtek urtwn(4) 11n USB devices, Ralink run(4) 11n USB devices, and iwn(4) iwm(4) Intel and Atheros athn(4) 11n PCIe (Mini) cards.

Using the network

Once you've booted NetBSD, you can see whether the card is detected and its current status with the wlanctl(8) and ifconfig(8) commands.

Most WiFi networks are protected using WPA, so you need to have wpa_supplicant(8) running:

# ifconfig athn0 up
# service wpa_supplicant onestart

Scan for available networks:

# wpa_cli scan_results
Selected interface 'athn0'
16:01:33.578: bssid / frequency / signal level / flags / ssid
xx:xx:xx:xx:xx:xx       5180    91      [WPA2-PSK-CCMP][ESS]    FRITZ!Box 1000 EZ

Trigger a rescan:

# wpa_cli scan

Configure wpa_supplicant to run on boot by editing /etc/rc.conf:

ifconfig_athn0="up"
dhcpcd=YES
wpa_supplicant=YES
wpa_supplicant_flags="-D bsd -i athn0 -c /etc/wpa_supplicant.conf"

The following example for /etc/wpa_supplicant.conf configures automatic connection a an open network FOSDEM-Dualstack:

network={
	ssid="FOSDEM-Dualstack"
	key_mgmt=NONE
	priority=100
}

The following example configures connecting to a closed network:

network={
	ssid="discord"
	psk="supersecretkey"
}

Once wpa_supplicant is configured, initialize dhcpcd(8) to obtain an IP address:

# service wpa_supplicant restart
# service dhcpcd restart

Acting as an access point

In order to configure an open network, use "mediaopt hostap" to ifconfig(8):

# ifconfig athn0 ssid mynet mediaopt hostap up

In order to configure a network with a password, you must use hostapd(8). Enable it in /etc/rc.conf:

ifconfig_athn0="up"
hostapd=YES

Place the configuration for your network in /etc/hostapd.conf. An example configuration can be found in /usr/share/examples/hostapd/hostapd.conf.

interface=athn0
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=mynet
macaddr_acl=0
# 1 = WPA, 2 = WEP, 3 = both
auth_algs=1
# WPA2 only
wpa=2
wpa_passphrase=SuperSecret12
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP

Other 802.11 tricks

Power-saving can be enabled with ifconfig athn0 powersave, use ifconfig athn0 -powersave to disable it again. You'll see ping times go up, but your power consumption should decrease.

Wireless cards do suck a lot of power; if you plan on using this while unplugged from the mains, it is recommended. You can do this from the command line, or, if you use powerd(8), you can control it automatically, with scripts in /etc/powerd/scripts.


Back to NetBSD Documentation: Network