Wi-Fi: Difference between revisions

From Alpine Linux
("Launching udhcpc through wpa_cli actions" rewrite, removing seemingly unnecessary autoscan modifications (these might be better-suited to a more instance-specific recommendation in a troubleshooting section))
m (rephrased sentence about Network manager)
 
(18 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This page describes how to set up a wireless network connection with WPA encryption.
This page describes how to set up a wireless network connection with WPA encryption using [[#wpa_supplicant|wpa_supplicant]].
 
Choose a wireless daemon between {{Pkg|iwd}} and {{Pkg|wpa_supplicant}}


== Prerequisites ==
== Prerequisites ==


Working wireless drivers  
Working wireless drivers. 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.
{{Note|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.}}
To list your available network interfaces:


If you are using a '''Broadcom chipset''', see the [[#Broadcom_Wi-Fi_Chipset_Users|Broadcom Wi-Fi section]].)
{{Cmd|ip link}}


== iwd ==
or


[[Iwd]] (iNet wireless daemon) is a wireless daemon written by Intel and aiming at replacing {{Pkg|wpa_supplicant}}. The core goal of the project is to optimize resource utilization by not depending on any external libraries and instead utilizing features provided by the Linux Kernel to the maximum extent possible.
{{Cmd|ip a}}


{{Pkg|iwd}} is supported since [https://alpinelinux.org/posts/Alpine-3.10.0-released.html Alpine Linux 3.10].
Refer to [[#Troubleshooting|Troubleshooting]] section to see if you don't see any wireless interfaces (e.g. {{Path|wlan0}}). You probably need to load and/or install drivers/firmware. If you are using a '''Broadcom chipset''', see the [[#Broadcom_Wi-Fi_Chipset_Users|Broadcom Wi-Fi section]].


To get started, install iwd:
Bring up the desired interface:
{{Cmd|# ip link set wlan0 up}}


{{Cmd|# apk add iwd}}
If this errors with <code>ioctl 0x8914 failed: No error information</code>, that's <code>busybox ip</code>'s way of saying your wireless radio is rfkill'd. See the [[#Rfkill|Rfkill section]] for information on how to unblock your wireless radio.


To do anything with iwd, it has to be running:
== iwd ==
{{main|iwd }}


{{Cmd|# rc-service iwd start}}
{{Tip| [[NetworkManager]],  the standard Linux network configuration tool suite supports both wireless daemons i.e [[iwd]] and [[#wpa_supplicant|wpa_supplicant]]. Using both may lead to conflicts.}}


If it was not running, running <code>iwctl ..</code> commands will print
== wpa_supplicant ==
 
  The name net.connman.iwd was not provided by any .service files 
Failed to retrieve IWD dbus objects, quitting...
 
and running just <code>iwctl</code> will say it is waiting for IWD to start.
 
List your available wifi device(s) (you probably have ''wlan0''):
 
{{Cmd|$ iwctl device list}}
 
If you don't know the SSID of your network you can run a scan and retrieve a list of all the detected networks:
 
{{Cmd|$ iwctl station wlan0 scan && iwctl station wlp8s0 get-networks}}
 
To connect to a network:
 
{{Cmd|$ iwctl station wlan0 connect <SSID>}}
 
<br>
 
{{Note|iwd automatically stores network passphrases in the /var/lib/iwd directory and uses them to auto-connect in the future. If you run diskless Alpine, make sure to include this directory to the apkovl and commit:
{{Cmd|# lbu add /var/lib/iwd && lbu commit -d}}}}
 
{{Note|Since version 1.10, iwd supports IPv6, but it is disabled by default. To enable it, add the following to the configuration file:
{{Cat|/etc/iwd/main.conf|<nowiki>[Network]
EnableIPv6=true</nowiki>}}}}


<br>
[[Configure_Networking#Network_setup-scripts|Network setup-scripts]] can configure your wifi quickly using <code>wpa_supplicant</code>. If it does not meet your requirement, please follow the steps outlined on this page.  
 
Finally, configure iwd and its dependency {{Pkg|dbus}} to start automatically on boot:
{{Cmd|# rc-update add iwd boot && rc-update add dbus boot}}
 
<br>
 
Add a entry for the desired interface (e.g. {{Path|wlan0}}):
{{Cat|/etc/network/interfaces|auto wlan0
iface wlan0 inet dhcp}}
 
{{Note|You could instead use the iwd's built-in network configuration by setting <code>EnableNetworkConfiguration{{=}}true</code> in {{Path|/etc/iwd/main.conf}}
{{Cat|/etc/iwd/main.conf|#[General]                                                                             
...
EnableNetworkConfiguration{{=}}True
...}}
}}
 
<br>
 
Manually restart '''networking''':
 
{{Cmd|# rc-service networking restart}}
 
<br>
 
Your wifi interface should now be up and have a dedicated IP adress:
{{Cmd|$ ip a show wlan0}}
 
<br>
 
Useful link: [https://wiki.archlinux.org/title/Iwd#Enable_built-in_network_configuration Archlinux wiki page] if you need more specific configuration.
 
== wpa_supplicant  ==


To get started install {{Pkg|wpa_supplicant}}
To get started install {{Pkg|wpa_supplicant}}


{{Cmd|# apk add wpa_supplicant}}
{{Cmd|# apk add wpa_supplicant}}
<br>
To list your available network interfaces:
{{Note|if you don't see any wireless interfaces (e.g. {{Path|wlan0}}), you probably need to load and/or install drivers/firmware.}}
<br>
{{Cmd|ip link}}
or
{{Cmd|ip a}}
<br>
Bring up the desired interface:
{{Cmd|# ip link set wlan0 up}}
{{Note|If this errors with <code>ioctl 0x8914 failed: No error information</code>, that's <code>busybox ip</code>'s way of saying your wireless radio is rfkill'd. See the [[#Rfkill|Rfkill section]] for information on how to unblock your wireless radio.}}
<br>


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


{{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}}
{{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}}
<br>


Start wpa_supplicant in the foreground to make sure the connection succeeds.
Start wpa_supplicant in the foreground to make sure the connection succeeds.
Line 123: Line 42:


<br>
<br>
If all is well, run it as a daemon in the background by setting the {{Path|-B}} option.
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 -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf}}


<br>
<br>
Configure the interface with an IP address.
Configure the interface with an IP address.
{{Cmd|# udhcpc -i wlan0}}
{{Cmd|# udhcpc -i wlan0}}
Line 140: Line 57:


Add a entry for the desired interface (e.g. {{Path|wlan0}}):
Add a entry for the desired interface (e.g. {{Path|wlan0}}):
{{Cat|/etc/network/interfaces|auto wlan0
{{Cat|/etc/network/interfaces|auto lo
auto wlan0
iface wlan0 inet dhcp}}
iface wlan0 inet dhcp}}


{{Note|Dont remove or comment out the '''auto lo''' entry}}
{{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.
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.
Line 152: Line 70:


<br>
<br>
Manually restart (or '''start''') '''networking'''.
Manually restart (or '''start''') '''networking'''.


{{Cmd|# /etc/init.d/networking --quiet restart &}}
{{Cmd|# rc-service networking --quiet restart &}}


<br>
<br>
Perform sanity checks like ping and browsing. For issues related to name resolution, refer [[Configure_Networking#Configuring_DNS|Networking]] page.


If all is well (feel free to confirm with the sanity checks),  
If all is well, Configure wpa_supplicant to start automatically on boot:
 
Configure wpa_supplicant to start automatically on boot:


{{Cmd|# rc-update add wpa_supplicant boot}}
{{Cmd|# rc-update add wpa_supplicant boot}}
<br>


Also make sure '''networking''' is set to automatically start on boot:
Also make sure '''networking''' is set to automatically start on boot:


{{Cmd|# rc-update add networking boot}}
{{Cmd|# rc-update add networking boot}}
<br>


'''Optional security precaution:'''
'''Optional security precaution:'''
Line 184: Line 96:


this is not necessary and {{Pkg|wpa_supplicant}} should funtion just fine without it, if you dont want your stored password in plain text just delete the line with <code>#psk="<YourPasswordShouldBeHereInPlainText>"</code> on it.
this is not necessary and {{Pkg|wpa_supplicant}} should funtion just fine without it, if you dont want your stored password in plain text just delete the line with <code>#psk="<YourPasswordShouldBeHereInPlainText>"</code> on it.
<br>


=== Launching udhcpc through wpa_cli actions ===
=== Launching udhcpc through wpa_cli actions ===
Line 198: Line 108:


<br>
<br>
To do this automatically, use the `wpa_cli` service included in {{Pkg|wpa_supplicant-openrc}}:
To do this automatically, use the `wpa_cli` service included in {{Pkg|wpa_supplicant-openrc}}:


Line 207: Line 116:
== Troubleshooting ==
== Troubleshooting ==


==== Broadcom Wi-Fi Chipset Users  ====
=== 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.
{{Cmd|# dmesg |grep wlan}}
or
{{Cmd|# dmesg}}
 
=== checking network cards ===
 
{{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:
 
{{Cmd|$ lspci -nn }}
{{Cmd|$ lsusb }}
 
Refer [[How to get regular stuff working#Hardware_Management|hardware management]], if the default outputs shown above 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 [https://wireless.wiki.kernel.org/en/users/Drivers/b43#list_of_hardware 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 cargs.  
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.  


You can check if you have a Broadcom chipset by using lspci:
To check what broadcom chip you have using lspci:


{{Cmd|$ lspci -nn -d 14e4:}}
{{Cmd|$ lspci -nn -d 14e4:}}


Now we need fwcutter:
====B43====


{{Cmd|# apk add b43-fwcutter}}
Download firmware cutter.
 
{{Cmd|$ apk add b43-fwcutter}}


Now we have everything to download the proprietary driver and extract the firmware from it:
Now we have everything to download the proprietary driver and extract the firmware from it:
Line 224: Line 154:
$ wget http://www.lwfinger.com/b43-firmware/broadcom-wl-5.100.138.tar.bz2
$ wget http://www.lwfinger.com/b43-firmware/broadcom-wl-5.100.138.tar.bz2
$ tar xjf 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>}}
$ 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].
More information can be found [http://linuxwireless.sipsolutions.net/en/users/Drivers/b43/#Other_distributions_not_mentioned_above here].
Line 234: Line 164:
Now continue with the normal instructions.  
Now continue with the normal instructions.  


<br>
====wl====
 
First install the software we need to build a driver[https://unix.stackexchange.com/questions/606073/how-to-build-kernel-modules-in-alpine-3-12 ^]:
 
{{Cmd|apk add git alpine-sdk linux-headers}}
 
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
}}
 
Then follow the build instructions listed in the git repo:
 
{{Cmd|make
doas make install
doas depmod -A
doas modprobe wl
}}


==== Rfkill ====
reboot and you have a working wl driver!


''See Also: [https://wiki.archlinux.org/title/Network_configuration/Wireless#Rfkill_caveat Network configuration/Wireless#Rfkill caveat - ArchLinux Wiki]''
Now continue with the normal instructions.  


<br>
=== Rfkill ===


Many laptops have a hardware button (or switch) to turn off wireless card, however, the card can also be blocked by kernel. This can be changed using rfkill. To show the current of your Wi-Fi:  
Many laptops have a hardware button (or switch) to turn off wireless card, however, the card can also be blocked by kernel. This can be changed using rfkill. To show the current of your Wi-Fi:  
Line 260: Line 208:
== See Also ==
== See Also ==


* [[Installation#Post-Install|Post Install]]
* [[Configure_Networking| Networking in Alpine Linux]]
* [[Alpine setup scripts]]
* [[Iwd|iwd]] - An alternate to wpa_supplicant
* [[Iwd|iwd]]
* [[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]


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

Latest revision as of 10:42, 18 October 2024

This page describes how to set up a wireless network connection with WPA encryption using wpa_supplicant.

Prerequisites

Working wireless drivers. 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. To list your available network interfaces:

ip link

or

ip a

Refer to Troubleshooting section to see if you don't see any wireless interfaces (e.g. wlan0). You probably need to load and/or install drivers/firmware. If you are using a Broadcom chipset, see the Broadcom Wi-Fi section.

Bring up the desired interface:

# ip link set wlan0 up

If this errors with ioctl 0x8914 failed: No error information, that's busybox ip's way of saying your wireless radio is rfkill'd. See the Rfkill section for information on how to unblock your wireless radio.

iwd

Tip: NetworkManager, the standard Linux network configuration tool suite supports both wireless daemons i.e iwd and wpa_supplicant. Using both may lead to conflicts.

wpa_supplicant

Network setup-scripts can configure your wifi quickly using wpa_supplicant. If it does not meet your requirement, please follow the steps outlined on this page.

To get started install wpa_supplicant

# 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 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 make sure the connection succeeds.

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


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


Automatic Configuration on System Boot

Add a entry for the desired interface (e.g. wlan0):

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 like ping and browsing. For issues related to name resolution, refer Networking page.

If all is well, Configure wpa_supplicant to start automatically on boot:

# rc-update add wpa_supplicant boot

Also make sure networking is set to automatically start on boot:

# rc-update add networking boot

Optional security precaution:

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

Contents of (Example) /etc/wpa_supplicant/wpa_supplicant.conf

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

this is not necessary and wpa_supplicant should funtion just fine without it, if you dont want your stored password in plain text just delete the line with #psk="<YourPasswordShouldBeHereInPlainText>" on it.

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"

# rc-update add wpa_cli boot

Troubleshooting

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

or

# 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 default outputs shown above 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

First install the software we need to build a driver^:

apk add git alpine-sdk linux-headers

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

Many laptops have a hardware button (or switch) to turn off wireless card, however, the card can also be blocked by kernel. This can be changed using rfkill. To show the current 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