Wi-Fi: Difference between revisions

From Alpine Linux
m (Add note about abuild-keygen)
(rephrased sentence, fixed wiki links and extra links)
(73 intermediate revisions by 23 users not shown)
Line 1: Line 1:
This document describes how to set up a wireless network connection with WPA encryption.
Alpine Linux supports two wireless daemons i.e [[#wpa_supplicant|wpa_supplicant]] and [[iwd]]. This page describes how to set up a wireless network connection using the default daemon [[#wpa_supplicant|wpa_supplicant]]. The [[iwd]] daemon is also fully supported in Alpine Linux. {{Note|Do not use both wireless daemons i.e [[#wpa_supplicant|wpa_supplicant]] and [[iwd]] simultaneously, as it leads to conflicts.}}


== Install necessary drivers and software  ==
== Prerequisites ==


First make sure your wireless drivers are loaded properly. (if you are using a '''Broadcom chipset''', see the [[#Broadcom_Wi-Fi_Chipset_Users|section at the bottom of this post]].)
Working wireless drivers. To list your available network interfaces use the commands {{ic|ip link}} or {{ic|ip a}}. Refer to [[#Troubleshooting|Troubleshooting]] section if you don't see any wireless interfaces (e.g. {{Path|wlan0}}).


Install {{Pkg|wireless-tools}} and {{Pkg|wpa_supplicant}}.
== Setup-interfaces ==
{{Cmd|apk add wireless-tools wpa_supplicant}}


== Manual Configuration ==
The [[Configure_Networking#setup-interfaces|setup-interfaces]] script automates the installation and configuration of
<code>wpa_supplicant</code> daemon to use Wi-Fi. [[NetworkManager]] can then be used to manage your Wi-Fi using various gui/tui tools.


Bring the link up so we can look for wireless networks. (An error here means you probably need extra drivers/firmware.)
== Manual configuration ==
{{Cmd|ip link set wlan0 up}}


Find a network to connect to. Look for the ESSID. In this example we will use the ESSID "MyNet".
To get started install {{Pkg|wpa_supplicant}} package: {{Cmd|# apk add wpa_supplicant}}
{{Cmd|iwlist wlan0 scanning}}


Configure the wlan0 interface to associate with the MyNet ESSID:
Use this command to add your Wi-Fi network to wpa_supplicant: {{Cmd|# wpa_passphrase 'ExampleWifiSSID' 'ExampleWifiPassword' > /etc/wpa_supplicant/wpa_supplicant.conf}}
{{Cmd|iwconfig wlan0 essid MyNet}}
''(Access point not broadcasting its SSID requires additional line <code>scan_ssid=1</code> in the file {{Path|/etc/wpa_supplicant/wpa_supplicant.conf}})''


Print its configuration, to check:
{{Note|the Wi-Fi SSID and password are case sensitive and the single quote before and after the SSID and password need to be there}}
{{Cmd|iwconfig wlan0}}


Create a wpa_supplicant configuration stanza for wpa_supplicant by executing the following:
Start wpa_supplicant in the foreground to check if wireless connection succeeds.{{Cmd|# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf}}
{{Cmd|wpa_passphrase MyNet > wpa.conf}}


wpa_passphrase expects the password to be passed via stdin. 
'''Optional security precaution:'''


So, type the password and press ENTER.
By default {{Pkg|wpa_supplicant}} will store your Wi-Fi password in plain text:{{Cat|/etc/wpa_supplicant/wpa_supplicant.conf|<nowiki>network={
    ssid="<YourSSIDShouldBeHere>"
The above commands creates the file {{Path|wpa.conf}} which includes the pre-shared key.
        #psk="<YourPasswordShouldBeHereInPlainText>"
    psk=<RandomLettersAndNumbersShouldBeHere>
}</nowiki>}}
If you dont want your stored password in plain text just delete the line with <code>#psk="<YourPasswordShouldBeHereInPlainText>"</code> on it.


From one terminal/console, start wpa_supplicant with the generated config:
If all is well, run it as a daemon in the background by setting the {{Path|-B}} option. {{Cmd|# wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf}}
{{Cmd|wpa_supplicant -Dwext -iwlan0 -c ./wpa.conf}}


From another terminal/console, start dhcpcd:
Configure the interface with an IP address.{{Cmd|# udhcpc -i wlan0}}
{{Cmd|udhcpc -i wlan0}}


The wlan0 interface should be configured with an IP address at this point:
Sanity check: the interface should have a {{Path|inet}} address. {{Cmd|$ ip addr show wlan0}}
{{Cmd|ifconfig wlan0}}


== Automatic Configuration on System Boot  ==
Add a entry for the desired interface (e.g. <code>wlan0</code>) in the file as follows:{{Cat|/etc/network/interfaces|auto lo
auto wlan0
iface wlan0 inet dhcp}}
 
{{Warning|Don't remove or comment out the '''auto lo''' entry}}
 
Sanity check: Make sure {{Path|/etc/wpa_supplicant/wpa_supplicant.conf}} is the correct configuration for the wireless access point you want to connect to.


Add an interface stanza for wlan0 to the file {{Path|/etc/network/interfaces}}
Bring the interface down. {{Cmd|# ip link set wlan0 down}}


<pre>
Manually restart (or '''start''') '''networking'''.{{Cmd|# rc-service networking --quiet restart &}}
auto wlan0
 
iface wlan0 inet dhcp
Perform [[Configure_Networking#Connectivity_testing|sanity checks]]. For issues related to name resolution, refer [[Configure_Networking#Configuring_DNS|Networking]] section.
</pre>


Create {{Path|/etc/wpa_supplicant}} if it doesn't already exist, set sane permissions and append the configuration {{Path|wpa.conf}} to {{Path|wpa_supplicant.conf}}.
=== Service configuration ===
{{Seealso|NetworkManager}}


<pre>
Proceed to configure wpa_supplicant service to start automatically on boot, if networking works properly: {{Cmd|# rc-update add wpa_supplicant boot}}
mkdir -p /etc/wpa_supplicant
Also ensure that '''networking''' is set to automatically start on boot: {{Cmd|# rc-update add networking boot}}
chmod 750 /etc/wpa_supplicant
cat wpa.conf >> /etc/wpa_supplicant/wpa_supplicant.conf
</pre>


Test the automatic interface configuration:
Manage wpa_supplicant service using the standard '''start''', '''stop''' and '''restart''' options. For eg: to start wpa_supplicant service: {{Cmd|# rc-service wpa_supplicant start}}


Bring the interface down:
=== Launching udhcpc through wpa_cli actions ===


{{Cmd|ifconfig wlan0 down}}
With the above configuration, udhcpc will only run once at boot. If the Wifi isn't available then, or the network changes after booting, udhcpc needs to be notified. You can automatically notify udhcpc of network changes by using a wpa_cli action file, such as the one installed by default at {{Path|/etc/wpa_supplicant/wpa_cli.sh}}.


Manually start wpa_supplicant
To manually start a wpa_cli daemon with an action file, use the `-a` option: {{Cmd|# wpa_cli -a /etc/wpa_supplicant/wpa_cli.sh}}


{{Cmd|/etc/init.d/wpa_supplicant start}}
To do this automatically, use the `wpa_cli` service included in {{Pkg|wpa_supplicant-openrc}}: {{Cat|/etc/conf.d/wpa_cli|<nowiki>WPACLI_OPTS="-a /etc/wpa_supplicant/wpa_cli.sh"</nowiki>}}
Add the service to start at boot: {{Cmd|# rc-update add wpa_cli boot}}


The wlan0 interface should be associated with the MyNet SSID:
== Troubleshooting ==


{{Cmd|iwconfig wlan0}}
If the commands {{ic|ip link}} or {{ic|ip a}} do not show any {{Path|wlan0}} interface, you probably need to load and/or install drivers/firmware. In most cases installing {{Pkg|linux-firmware}} should get you the required drivers. Installation of this package can produce errors on diskless or data disk modes. If such errors occur, switch to system disk mode.


The wlan0 interface should have been assigned an IP address via DHCP:
If you are using a '''Broadcom chipset''', see the [[#Broadcom_Wi-Fi_Chipset_Users|Broadcom Wi-Fi section]].


{{Cmd|ifconfig wlan0}}
Bring up the desired interface: {{Cmd|# ip link set wlan0 up}}


Configure wpa_supplicant to start automatically on boot:
=== Check dmesg ===


{{Cmd|rc-update add wpa_supplicant boot}}
Run dmesg and check for errors related to the wireless interface. Usually, dmesg gives maximum information related to network and all other hardware.
{{Cmd|# dmesg}}


Reboot:
=== checking network cards ===


{{Cmd|reboot}}
{{Cmd|$ cat /proc/net/dev }} lists the network interfaces that are detected. If the expected interfaces are not available, Check what network hardware chip you have using lspci or lsusb:


Log in and check that the interface is associated with the access point:
{{Cmd|$ lspci -nn }}
{{Cmd|$ lsusb }}


{{Cmd|iwconfig wlan0}}
Refer [[How to get regular stuff working#Hardware_Management|hardware management]], if the above output lacks sufficient information.


Check that the interface was assigned an IP address via DHCP:
Check what driver the card uses and modprobe it. Check that the card is in master mode.
Check what driver you need on the [https://wireless.wiki.kernel.org/en/users/Drivers/b43#list_of_hardware b43 compatibility page]


{{Cmd|ifconfig wlan0 {{!}} grep addr}}
=== Broadcom Wi-Fi Chipset Users  ===


== Broadcom Wi-Fi Chipset Users  ==
The Broadcom chipset is quite popular among older computers. The b43 driver is included in the linux-lts or linux-edge kernel packages. However, you might need to compile the firmware manually for this chipset as it is not included in linux-firmware for some cards.


The Broadcom chipset is quite popular among older computers. You will need to compile the firmware manually for this chipset as it is not included.
To check what broadcom chip you have using lspci:


You can check if you have a Broadcom chipset by using dmesg:
{{Cmd|$ lspci -nn -d 14e4:}}


{{Cmd|dmesg {{!}} grep Broadcom}}
====B43====


First install the SDK an Git:
Download firmware cutter. {{Cmd|$ apk add b43-fwcutter}}
{{Cmd|apk add alpine-sdk git}}


Then git clone aports from git.alpinelinux.org.
Now we have everything to download the proprietary driver and extract the firmware from it: {{Cmd|<nowiki># export FIRMWARE_INSTALL_DIR="/lib/firmware"
$ wget http://www.lwfinger.com/b43-firmware/broadcom-wl-5.100.138.tar.bz2
$ tar xjf broadcom-wl-5.100.138.tar.bz2
$ b43-fwcutter -w "$FIRMWARE_INSTALL_DIR" broadcom-wl-5.100.138/linux/wl_apsta.o</nowiki>}}


More information can be found [http://linuxwireless.sipsolutions.net/en/users/Drivers/b43/#Other_distributions_not_mentioned_above here].


{{Cmd|git clone git://git.alpinelinux.org/aports}}
Now you need to use modprobe so the device will show up: {{Cmd|# modprobe b43}}


Change your directory to '''aports/non-free/b43-firmware''', then build it.
Now continue with the normal instructions.  


{{Tip|You can't be root and must be a user of the group abuild (use groupadd f.e. '''groupadd $(whoami) abuild''')}}
====wl ====
{{Tip|If this is your first time building a package you will need to generate a key for use in signing packages (use '''abuild-keygen -a -i''')}}


{{Cmd|abuild -r}}
You can use APKBUILD from [https://codeberg.org/NeYurii/broadcom-wl here]. It uses [[Alpine kernel module support]] for automatic building and updating driver for new kernel versions. Instructions can be found in the [https://codeberg.org/NeYurii/broadcom-wl broadcom-wl repository].


Install the generated packge file (it will be in ~/packages/) - make sure to pass '''--allow-untrusted'''
Alternately, install the software to build a driver: {{Cmd|apk add git alpine-sdk linux-headers linux-lts-dev}}


{{Cmd|apk add --allow-untrusted ~/packages/...pkg}}
Then install the driver build repo (this is archived, however it's legacy so that doesn't matter): {{Cmd|git clone https://github.com/antoineco/broadcom-wl
cd broadcom-wl
}}


Now we need fwcutter, which is executed from the firmware package:
Then follow the build instructions listed in the git repo: {{Cmd|make
doas make install
doas depmod -A
doas modprobe wl
}}


{{Cmd|apk add b43-fwcutter b43-firmware}}
Reboot and you have a working wl driver. Now continue with the normal instructions.


Now you need to use modprobe so the device will show up:
=== Rfkill ===


{{Cmd|modprobe b43}}
An error message <code>ioctl 0x8914 failed: No error information</code>, is the <code>busybox ip</code>'s way of saying your wireless radio is rfkilled, which means the wireless card is blocked by kernel. This can be changed using rfkill. To show the current status of your Wi-Fi:
<p style="background-color:#f9f9f9; border:1px dashed #2f6fab; line-height:1.1em; padding:1em; font-family:monospace; font-size:10pt; white-space:pre; overflow:auto;"><span style="color:green;">~</span>'''$''' rfkill list
0: phy0: wlan
    Soft blocked: no
    Hard blocked: no
</p>


To automate this on startup add it to /etc/modules:
If the card is hard-blocked, use the hardware button or switch to unblock it. If the card is not hard-blocked but soft-blocked, use the following command: {{Cmd|# rfkill unblock wifi}}


{{Cmd|echo b43 >> /etc/modules}}
== See also ==


Now continue with the normal instructions.  
* [[Configure_Networking| Networking in Alpine Linux]]
* [[Iwd|iwd]] - An alternate to wpa_supplicant
* [[NetworkManager]] - Front-end to Networking
* [https://wiki.postmarketos.org/wiki/WiFi PostmarketOS Wiki]
* [https://wiki.archlinux.org/title/Network_configuration/Wireless Archwiki]
* [https://wiki.gentoo.org/wiki/Wi-Fi Gentoo Wiki]
* [[Alpine kernel module support]] - A fully automated solution for building kernel modules
* [https://unix.stackexchange.com/questions/606073/how-to-build-kernel-modules-in-alpine-3-12 Build kernel modules manually]


[[Category:Networking]]
[[Category:Networking]]

Revision as of 06:13, 21 March 2025

Alpine Linux supports two wireless daemons i.e wpa_supplicant and iwd. This page describes how to set up a wireless network connection using the default daemon wpa_supplicant. The iwd daemon is also fully supported in Alpine Linux.

Note: Do not use both wireless daemons i.e wpa_supplicant and iwd simultaneously, as it leads to conflicts.

Prerequisites

Working wireless drivers. To list your available network interfaces use the commands ip link or ip a. Refer to Troubleshooting section if you don't see any wireless interfaces (e.g. wlan0).

Setup-interfaces

The setup-interfaces script automates the installation and configuration of wpa_supplicant daemon to use Wi-Fi. NetworkManager can then be used to manage your Wi-Fi using various gui/tui tools.

Manual configuration

To get started install wpa_supplicant package:

# apk add wpa_supplicant

Use this command to add your Wi-Fi network to wpa_supplicant:

# wpa_passphrase 'ExampleWifiSSID' 'ExampleWifiPassword' > /etc/wpa_supplicant/wpa_supplicant.conf

(Access point not broadcasting its SSID requires additional line scan_ssid=1 in the file /etc/wpa_supplicant/wpa_supplicant.conf)

Note: the Wi-Fi SSID and password are case sensitive and the single quote before and after the SSID and password need to be there

Start wpa_supplicant in the foreground to check if wireless connection succeeds.

# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

Optional security precaution:

By default wpa_supplicant will store your Wi-Fi password in plain text:

Contents of /etc/wpa_supplicant/wpa_supplicant.conf

network={ ssid="<YourSSIDShouldBeHere>" #psk="<YourPasswordShouldBeHereInPlainText>" psk=<RandomLettersAndNumbersShouldBeHere> }

If you dont want your stored password in plain text just delete the line with #psk="<YourPasswordShouldBeHereInPlainText>" on it.

If all is well, run it as a daemon in the background by setting the -B option.

# wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

Configure the interface with an IP address.

# udhcpc -i wlan0

Sanity check: the interface should have a inet address.

$ ip addr show wlan0

Add a entry for the desired interface (e.g. wlan0) in the file as follows:

Contents of /etc/network/interfaces

auto lo auto wlan0 iface wlan0 inet dhcp
Warning: Don't remove or comment out the auto lo entry


Sanity check: Make sure /etc/wpa_supplicant/wpa_supplicant.conf is the correct configuration for the wireless access point you want to connect to.

Bring the interface down.

# ip link set wlan0 down

Manually restart (or start) networking.

# rc-service networking --quiet restart &

Perform sanity checks. For issues related to name resolution, refer Networking section.

Service configuration

Proceed to configure wpa_supplicant service to start automatically on boot, if networking works properly:

# rc-update add wpa_supplicant boot

Also ensure that networking is set to automatically start on boot:

# rc-update add networking boot

Manage wpa_supplicant service using the standard start, stop and restart options. For eg: to start wpa_supplicant service:

# rc-service wpa_supplicant start

Launching udhcpc through wpa_cli actions

With the above configuration, udhcpc will only run once at boot. If the Wifi isn't available then, or the network changes after booting, udhcpc needs to be notified. You can automatically notify udhcpc of network changes by using a wpa_cli action file, such as the one installed by default at /etc/wpa_supplicant/wpa_cli.sh.

To manually start a wpa_cli daemon with an action file, use the `-a` option:

# wpa_cli -a /etc/wpa_supplicant/wpa_cli.sh

To do this automatically, use the `wpa_cli` service included in wpa_supplicant-openrc:

Contents of /etc/conf.d/wpa_cli

WPACLI_OPTS="-a /etc/wpa_supplicant/wpa_cli.sh"

Add the service to start at boot:

# rc-update add wpa_cli boot

Troubleshooting

If the commands ip link or ip a do not show any wlan0 interface, you probably need to load and/or install drivers/firmware. In most cases installing linux-firmware should get you the required drivers. Installation of this package can produce errors on diskless or data disk modes. If such errors occur, switch to system disk mode.

If you are using a Broadcom chipset, see the Broadcom Wi-Fi section.

Bring up the desired interface:

# ip link set wlan0 up

Check dmesg

Run dmesg and check for errors related to the wireless interface. Usually, dmesg gives maximum information related to network and all other hardware.

# dmesg

checking network cards

$ cat /proc/net/dev

lists the network interfaces that are detected. If the expected interfaces are not available, Check what network hardware chip you have using lspci or lsusb:

$ lspci -nn

$ lsusb

Refer hardware management, if the above output lacks sufficient information.

Check what driver the card uses and modprobe it. Check that the card is in master mode. Check what driver you need on the b43 compatibility page

Broadcom Wi-Fi Chipset Users

The Broadcom chipset is quite popular among older computers. The b43 driver is included in the linux-lts or linux-edge kernel packages. However, you might need to compile the firmware manually for this chipset as it is not included in linux-firmware for some cards.

To check what broadcom chip you have using lspci:

$ lspci -nn -d 14e4:

B43

Download firmware cutter.

$ apk add b43-fwcutter

Now we have everything to download the proprietary driver and extract the firmware from it:

# export FIRMWARE_INSTALL_DIR="/lib/firmware" $ wget http://www.lwfinger.com/b43-firmware/broadcom-wl-5.100.138.tar.bz2 $ tar xjf broadcom-wl-5.100.138.tar.bz2 $ b43-fwcutter -w "$FIRMWARE_INSTALL_DIR" broadcom-wl-5.100.138/linux/wl_apsta.o

More information can be found here.

Now you need to use modprobe so the device will show up:

# modprobe b43

Now continue with the normal instructions.

wl

You can use APKBUILD from here. It uses Alpine kernel module support for automatic building and updating driver for new kernel versions. Instructions can be found in the broadcom-wl repository.

Alternately, install the software to build a driver:

apk add git alpine-sdk linux-headers linux-lts-dev

Then install the driver build repo (this is archived, however it's legacy so that doesn't matter):

git clone https://github.com/antoineco/broadcom-wl cd broadcom-wl

Then follow the build instructions listed in the git repo:

make doas make install doas depmod -A doas modprobe wl

Reboot and you have a working wl driver. Now continue with the normal instructions.

Rfkill

An error message ioctl 0x8914 failed: No error information, is the busybox ip's way of saying your wireless radio is rfkilled, which means the wireless card is blocked by kernel. This can be changed using rfkill. To show the current status of your Wi-Fi:

~$ rfkill list 0: phy0: wlan Soft blocked: no Hard blocked: no

If the card is hard-blocked, use the hardware button or switch to unblock it. If the card is not hard-blocked but soft-blocked, use the following command:

# rfkill unblock wifi

See also