Wi-Fi: Difference between revisions

From Alpine Linux
m (improved essid configuration steps)
(31 intermediate revisions by 8 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  ==
== 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  
{{Note|in most cases installing {{Pkg|linux-firmware}} should get you the required drivers}}


Install {{Pkg|wireless-tools}} and {{Pkg|wpa_supplicant}}.
If you are using a '''Broadcom chipset''', see the [[#Broadcom_Wi-Fi_Chipset_Users|Broadcom Wi-Fi section]].)
{{Cmd|apk add wireless-tools wpa_supplicant}}


== Manual Configuration ==
<br>
 
== wpa_supplicant ==
 
To get started install {{Pkg|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>


List your available network interfaces. If you don't see any wireless interfaces (e.g. {{Path|wlan0}}), you probably need to load and/or install extra drivers/firmware.
{{Cmd|ip link}}
{{Cmd|ip link}}
or
{{Cmd|ip a}}
<br>


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


Use the interface to scan for wireless access points. Make sure the ESSID you want to connect to appears here.
{{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.}}
{{Cmd|iwlist wlan0 scanning}}
 
<br>


Associate the interface with desired ESSID.
Use this command to add your Wi-Fi network to wpa_supplicant:
{{Cmd|iwconfig wlan0 essid ExampleWifi}}
{{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>)''


Sanity check: the interface should be configured with {{Path|ESSID:"ExampleWifi"}}.
{{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:
<br>
{{Cmd|wpa_passphrase ExampleWifi > wpa.conf}} 


wpa_passphrase expects the password to be passed via stdin.
Start wpa_supplicant in the foreground to make sure the connection succeeds.
{{Cmd|wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf}}


So, type the password and press ENTER.
<br>
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:
If all is well, run it as a daemon in the background by setting the {{Path|-B}} option.
{{Cmd|wpa_supplicant -Dwext -iwlan0 -c ./wpa.conf}}
{{Cmd|wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf}}


From another terminal/console, start dhcpcd:
<br>
 
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|ifconfig wlan0}}
{{Cmd|ip addr show wlan0}}


== Automatic Configuration on System Boot  ==
<br>


Add an interface stanza for wlan0 to the file {{Path|/etc/network/interfaces}}
==== Automatic Configuration on System Boot  ====
 
Add a entry for the desired interface (e.g. {{Path|wlan0}}) to {{Path|/etc/network/interfaces}}:


<pre>
<pre>
Line 52: Line 71:
</pre>
</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|Dont remove or comment out the '''auto lo''' entry}}


<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:
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:
<br>


{{Cmd|ifconfig wlan0 down}}
Bring the interface down.


Manually start wpa_supplicant
{{Cmd|ip link set wlan0 down}}


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


The wlan0 interface should be associated with the MyNet SSID:
Manually restart (or '''start''') '''networking'''.


{{Cmd|iwconfig wlan0}}
{{Cmd|/etc/init.d/networking --quiet restart &}}


The wlan0 interface should have been assigned an IP address via DHCP:
<br>


{{Cmd|ifconfig wlan0}}
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}}
 
<br>
 
Also make sure '''networking''' is set to automatically start on boot:
 
{{Cmd|# rc-update add networking boot}}
 
<br>


Reboot:
'''Optional security precaution:'''


{{Cmd|reboot}}
By default {{Pkg|wpa_supplicant}} will store your Wi-Fi password in plain text:


Log in and check that the interface is associated with the access point:
{{Cat|(Example) /etc/wpa_supplicant/wpa_supplicant.conf|<nowiki>network={
ssid="<YourSSIDShouldBeHere>"
        #psk="<YourPasswordShouldBeHereInPlainText>"
psk=<RandomLettersAndNumbersShouldBeHere>
}</nowiki>}}


{{Cmd|iwconfig wlan0}}
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.


Check that the interface was assigned an IP address via DHCP:
<br>


{{Cmd|ifconfig wlan0 {{!}} grep addr}}
== Launching udhcpc through wpa_cli actions ==


=== Launching udhcpc through wpa_cli actions ===
{{Todo|Figure out if theses two sections are different or connected to one another}}


With the above configuration, udhcpc will only run once at boot.
With the above configuration, udhcpc will only run once at boot.
If the Wifi isn't available then, or the network changes in between, it needs to be notified.
If the Wifi isn't available then, or the network changes in between, it needs to be notified.
This is done through the wpa_cli action script in /etc/wpa_supplicant/wpa_cli.sh
This is done through the wpa_cli action script in /etc/wpa_supplicant/wpa_cli.sh
== Automatic Reconnection when WIFI signal is lost  ==
To enable automatic reconnection when wifi signal is lost add these to config:
{{Cat|/etc/wpa_supplicant/wpa_supplicant.conf|
<nowiki>
ap_scan=1
autoscan=periodic:10
disable_scan_offload=1
</nowiki>
}}


{{Cmd|rc-update add wpa_cli boot}}
{{Cmd|rc-update add wpa_cli boot}}


== Broadcom Wi-Fi Chipset Users  ==
<br>
 
== Troubleshooting ==
 
==== Broadcom Wi-Fi Chipset Users  ====


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.  
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.  
Line 110: Line 153:
{{Cmd|dmesg {{!}} grep Broadcom}}
{{Cmd|dmesg {{!}} grep Broadcom}}


First install the SDK an Git:
First install the SDK and Git:
{{Cmd|apk add alpine-sdk git}}
{{Cmd|apk add alpine-sdk git}}


Line 120: Line 163:
Change your directory to '''aports/non-free/b43-firmware''', then build it.
Change your directory to '''aports/non-free/b43-firmware''', then build it.


{{Tip|You can't be root and must be a user of the group abuild (use groupadd f.e. '''groupadd $(whoami) abuild''')}}
{{Tip|You can't be root and must be a user of the group abuild (use groupadd f.e. '''addgroup $(whoami) abuild''')}}
{{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''')}}
{{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''')}}


Line 142: Line 185:


Now continue with the normal instructions.  
Now continue with the normal instructions.  
<br>
==== Rfkill ====
''See Also: [https://wiki.archlinux.org/title/Network_configuration/Wireless#Rfkill_caveat Network configuration/Wireless#Rfkill caveat - ArchLinux Wiki]''
<br>
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:
{{Cat|(example) $ rfkill list|0: phy0: wlan
Soft blocked: no
Hard blocked: no}}
<br>
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}}
<br>
== See Also ==
* [[Installation]]
* [[Post installation]]
* [[Alpine setup scripts]]


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

Revision as of 20:19, 4 January 2022

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

Prerequisites

Working wireless drivers

Note: in most cases installing linux-firmware should get you the required drivers

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


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) to /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.

/etc/init.d/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

Todo: Figure out if theses two sections are different or connected to one another


With the above configuration, udhcpc will only run once at boot. If the Wifi isn't available then, or the network changes in between, it needs to be notified. This is done through the wpa_cli action script in /etc/wpa_supplicant/wpa_cli.sh

Automatic Reconnection when WIFI signal is lost

To enable automatic reconnection when wifi signal is lost add these to config:

Contents of /etc/wpa_supplicant/wpa_supplicant.conf

ap_scan=1 autoscan=periodic:10 disable_scan_offload=1


rc-update add wpa_cli boot


Troubleshooting

Broadcom Wi-Fi Chipset Users

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.

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

dmesg | grep Broadcom

First install the SDK and Git:

apk add alpine-sdk git

Then git clone aports from git.alpinelinux.org.


git clone git://git.alpinelinux.org/aports

Change your directory to aports/non-free/b43-firmware, then build it.

Tip: You can't be root and must be a user of the group abuild (use groupadd f.e. addgroup $(whoami) abuild)
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)

abuild -r

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

apk add --allow-untrusted ~/packages/...pkg

Now we need fwcutter, which is executed from the firmware package:

apk add b43-fwcutter b43-firmware

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

modprobe b43

To automate this on startup add it to /etc/modules:

echo b43 >> /etc/modules

Now continue with the normal instructions.


Rfkill

See Also: Network configuration/Wireless#Rfkill caveat - ArchLinux Wiki


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:

Contents of (example) $ 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