Wi-Fi

From Leo's Notes
Last edited on 30 December 2021, at 02:00.

Monitoring Access Points

To monitor data on the wifi network, install aircrack-ng, then run:

# airomon-ng start wlan0
# airodump-ng wlan0

You may get an error like:

[root@alarmpi ~]# airodump-ng wlan0
ioctl(SIOCSIWMODE) failed: Device or resource busy

ARP linktype is set to 1 (Ethernet) - expected ARPHRD_IEEE80211,
ARPHRD_IEEE80211_FULL or ARPHRD_IEEE80211_PRISM instead.  Make
sure RFMON is enabled: run 'airmon-ng start wlan0 <#>'
Sysfs injection support was not found either.

Make sure that the wireless device is in the monitor mode and then try again.

[root@alarmpi ~]# iwconfig wlan0
wlan0     IEEE 802.11bgn  ESSID:off/any
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off

[root@alarmpi ~]# ifconfig wlan0 down
[root@alarmpi ~]# iwconfig wlan0 mode monitor
[root@alarmpi ~]# ifconfig wlan0 up
[root@alarmpi ~]# iwconfig wlan0
wlan0     IEEE 802.11bgn  Mode:Monitor  Frequency:2.422 GHz  Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off

Automatically Connecting

Install wpa_supplicant since it's required to connect to wpa networks:

# pacman -S wpa_supplicant

You will need to create a netctl profile in /etc/netctl. This can be done either manually or through the wifi-menu command. Example WPA configuration files can be viewed in /etc/netctl/examples/wireless-wpa and can be copied to /etc/netctl and used as a template configuration file.

# cat /etc/netctl/wlan0-dd-wrt
Description='Automatically generated profile by wifi-menu'
Interface=wlan0
Connection=wireless
Security=wpa
ESSID=dd-wrt
IP=dhcp
Key=\"f0c8a9e643*************************************************af10f

Your Key can be your password or the PSK key generated using wpa_passphrase. wifi-menu will automatically generate and use the PSK key instead of storing the plain text copy of the password.

#  wpa_passphrase dd-wrt ap_password
network={
        ssid="dd-wrt"
        #psk="ap_password"
        psk=14c5441f17e930da158a71592c3c7914315424f08d03c225d1092076093c32ee
}

You can then connect to the access point by running:

# netctl start $profile-name

If it errors out, check the systemd logs using journalctl -xe. If you're still having issues connecting, you may want to try reseating the wireless device or rebooting the machine.

To make the machine join a wireless access point automatically, create a startup script (see Systemd for more information) containing:

#!/bin/sh
sh -c 'while ! netctl start wlan0-dd-wrt ; do echo Wi-Fi failed to come up. Retrying ; sleep 1 ; done'

See Also