Wi-Fi: Difference between revisions

From Alpine Linux
(Separate manual from automatic configuration and add more detail for less experienced users.)
m (Fix spelling of "cards" under ==== Broadcom Wi-Fi Chipset Users ====)
 
(55 intermediate revisions by 20 users not shown)
Line 1: Line 1:
This document 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.


== Install necessary drivers and software  ==
Choose a wireless daemon between {{Pkg|iwd}} and {{Pkg|wpa_supplicant}}


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]].)
== Prerequisites ==


Install {{Pkg|wireless-tools}} and {{Pkg|wpa_supplicant}}.
Working wireless drivers
{{Cmd|apk add wireless-tools wpa_supplicant}}
{{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.}}


== Manual Configuration  ==
If you are using a '''Broadcom chipset''', see the [[#Broadcom_Wi-Fi_Chipset_Users|Broadcom Wi-Fi section]].)


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


Find a network to connect to. Look for the ESSID. In this example we will use the ESSID "MyNet".
Iwd (iNet wireless daemon) is a wireless daemon written by Intel and aiming at replacing {{Pkg|wpa_supplicant|arch=}}. 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|iwlist wlan0 scanning}}


Configure the wlan0 interface to associate with the MyNet ESSID:
{{Pkg|iwd|arch=}} is supported since [https://alpinelinux.org/posts/Alpine-3.10.0-released.html Alpine Linux 3.10].
{{Cmd|iwconfig wlan0 essid MyNet}}


Print its configuration, to check:
See the [[iwd|iwd article]] for more information
{{Cmd|iwconfig wlan0}}


Create a wpa_supplicant configuration stanza for wpa_supplicant by executing the following:
== wpa_supplicant  ==
{{Cmd|wpa_passphrase MyNet > wpa.conf}}  


wpa_passphrase expects the password to be passed via stdin. 
To get started install {{Pkg|wpa_supplicant}}


So, type the password and press ENTER.
{{Cmd|# apk add wpa_supplicant}}
The above commands creates the file {{Path|wpa.conf}} which includes the pre-shared key. 


From one terminal/console, start wpa_supplicant with the generated config:
<br>
{{Cmd|wpa_supplicant -Dwext -iwlan0 -c ./wpa.conf}}


From another terminal/console, start dhcpcd:
To list your available network interfaces:
{{Cmd|udhcpc -i wlan0}}
{{Note|if you don't see any wireless interfaces (e.g. {{Path|wlan0}}), you probably need to load and/or install drivers/firmware.}}


The wlan0 interface should be configured with an IP address at this point:
<br>
{{Cmd|ifconfig wlan0}}


== Automatic Configuration on System Boot  ==
{{Cmd|ip link}}
or
{{Cmd|ip a}}


Add an interface stanza for wlan0 to the file {{Path|/etc/network/interfaces}}
<br>


<pre>
Bring up the desired interface:
auto wlan0
{{Cmd|# ip link set wlan0 up}}
iface wlan0 inet dhcp
</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}}.
{{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.}}


<pre>
<br>
mkdir -p /etc/wpa_supplicant
chmod 750 /etc/wpa_supplicant
cat wpa.conf >> /etc/wpa_supplicant/wpa_supplicant.conf
</pre>


Test the automatic interface configuration:
Use this command to add your Wi-Fi network to wpa_supplicant:
{{Cmd|# wpa_passphrase 'ExampleWifiSSID' 'ExampleWifiPassword' > /etc/wpa_supplicant/wpa_supplicant.conf}}
''(Access point not broadcasting its SSID requires additional line <code>scan_ssid=1</code> in the file <code>wpa_supplicant.conf</code>)''


Bring the interface down:
{{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|ifconfig wlan0 down}}
<br>


Manually start wpa_supplicant
Start wpa_supplicant in the foreground to make sure the connection succeeds.
{{Cmd|# wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf}}


{{Cmd|/etc/init.d/wpa_supplicant start}}
<br>


The wlan0 interface should be associated with the MyNet SSID:
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|iwconfig wlan0}}
<br>


The wlan0 interface should have been assigned an IP address via DHCP:
Configure the interface with an IP address.
{{Cmd|# udhcpc -i wlan0}}


{{Cmd|ifconfig wlan0}}
Sanity check: the interface should have a {{Path|inet}} address.
{{Cmd|$ ip addr show wlan0}}
 
<br>
 
=== Automatic Configuration on System Boot  ===
 
Add a entry for the desired interface (e.g. {{Path|wlan0}}):
{{Cat|/etc/network/interfaces|auto wlan0
iface wlan0 inet dhcp}}
 
{{Note|Dont 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.
 
Bring the interface down.
 
{{Cmd|# ip link set wlan0 down}}
 
<br>
 
Manually restart (or '''start''') '''networking'''.
 
{{Cmd|# rc-service networking --quiet restart &}}
 
<br>
 
If all is well (feel free to confirm with the sanity checks),


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


Reboot:
<br>


{{Cmd|reboot}}
Also make sure '''networking''' is set to automatically start on boot:


Log in and check that the interface is associated with the access point:
{{Cmd|# rc-update add networking boot}}


{{Cmd|iwconfig wlan0}}
<br>


Check that the interface was assigned an IP address via DHCP:
'''Optional security precaution:'''


{{Cmd|ifconfig wlan0 {{!}} grep addr}}
By default {{Pkg|wpa_supplicant}} will store your Wi-Fi password in plain text:


== Broadcom Wi-Fi Chipset Users  ==
{{Cat|(Example) /etc/wpa_supplicant/wpa_supplicant.conf|<nowiki>network={
    ssid="<YourSSIDShouldBeHere>"
        #psk="<YourPasswordShouldBeHereInPlainText>"
    psk=<RandomLettersAndNumbersShouldBeHere>
}</nowiki>}}


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.  
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.


You can check if you have a Broadcom chipset by using dmesg:
<br>


{{Cmd|dmesg {{!}} grep Broadcom}}
=== Launching udhcpc through wpa_cli actions ===


First install the SDK an Git:
With the above configuration, udhcpc will only run once at boot.
{{Cmd|apk add alpine-sdk git}}
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`.


Then git clone aports from git.alpinelinux.org.
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|git clone git://git.alpinelinux.org/aports}}
<br>


Change your directory to '''aports/non-free/b43-firmware''', then build it.
To do this automatically, use the `wpa_cli` service included in {{Pkg|wpa_supplicant-openrc}}:


''You can't be root and must be a user of the group abuild (use groupadd)''
{{Cat|/etc/conf.d/wpa_cli|<nowiki>WPACLI_OPTS="-a /etc/wpa_supplicant/wpa_cli.sh"</nowiki>}}


{{Cmd|abuild -r}}
{{Cmd|# rc-update add wpa_cli boot}}


Install the generated packge file (it will be in ~/packages/) - make sure to pass '''--allow-untrusted'''
== Troubleshooting ==


{{Cmd|apk add --allow-untrusted ~/packages/...pkg}}
==== Broadcom Wi-Fi Chipset Users  ====


Now we need fwcutter, which is executed from the firmware package:
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.


{{Cmd|apk add b43-fwcutter b43-firmware}}
You can check if you have a Broadcom chipset by using lspci:
 
{{Cmd|$ lspci -nn -d 14e4:}}
 
Now we need fwcutter:
 
{{Cmd|# apk add b43-fwcutter}}
 
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].


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


{{Cmd|modprobe b43}}
{{Cmd|# modprobe b43}}
 
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:
 
<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>
 
<br>


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|echo b43 >> /etc/modules}}
{{Cmd|# rfkill unblock wifi}}
 
<br>
 
== See Also ==
 
* [[Installation#Post-Install|Post Install]]
* [[Alpine setup scripts]]
* [[Iwd|iwd]]
* [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]


Now continue with the normal instructions.


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

Latest revision as of 15:45, 6 March 2024

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

Choose a wireless daemon between iwd and wpa_supplicant

Prerequisites

Working wireless drivers

Note: 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.)

iwd

Iwd (iNet wireless daemon) is a wireless daemon written by Intel and aiming at replacing 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.

iwd is supported since Alpine Linux 3.10.

See the iwd article for more information

wpa_supplicant

To get started install wpa_supplicant

# apk add wpa_supplicant


To list your available network interfaces:

Note: if you don't see any wireless interfaces (e.g. wlan0), you probably need to load and/or install drivers/firmware.


ip link

or

ip a


Bring up the desired interface:

# ip link set wlan0 up

Note: 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.


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 wlan0 iface wlan0 inet dhcp
Note: Dont 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 &


If all is well (feel free to confirm with the sanity checks),

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

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.

You can check if you have a Broadcom chipset by using lspci:

$ lspci -nn -d 14e4:

Now we need fwcutter:

# 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.


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