Command-line WiFi configuration

Last modified: Sun Jun 2 10:50:52 EDT 2019

2012-04, Slackware 13.37

I never could get WiFi to work using the normal Slackware approach with configurables set in /etc/rc.d/rc.inet1.conf.  A lot of people skip it and use Wicd, but the following workarounds worked for me and are not that complicated.

Preconditions

Configuration 1:  Unsecure, no-password WiFi + DHCP

Lines for /etc/rc.d/rc.local:

echo Connecting to WiFi...
/sbin/iwconfig wlan0 mode Managed essid "Hotel's SSID here" enc off
sleep 5
/sbin/dhcpcd -t 10 -C resolv.conf wlan0 >& /tmp/dhcpcd.txt

# Get addresses of this computer and the router as determined by DHCP
IPADDR=`fgrep leased /tmp/dhcpcd.txt | cut -f 4 -d " "`
ROUTER=`fgrep acknowledged /tmp/dhcpcd.txt | cut -f 6 -d " "`
# Configure iptables as desired

The –C switch to dhcpcd says to use the DNS server already specified in /etc/resolv.conf rather than whatever DHCP suggests.

Configuration 2:  WPA2-PSK + static IP

Lines for /etc/rc.d/rc.local:

echo Connecting to WiFi...
wpa_supplicant -B -c/etc/wpa_supplicant.conf -Dwext -iwlan0 >& /tmp/wpa_supplicant_log.txt
sleep 5
# Change 192.168.1.5 to your static IP and other fields accordingly.
/sbin/ifconfig wlan0 192.168.1.5 broadcast 192.168.1.255 netmask 255.255.255.0
/sbin/route add default gw 192.168.1.1 metric 1
# Configure iptables as desired

Example WPA2 configuration in /etc/wpa_supplicant.conf:

# Stuff that might be unnecessary or wrong.
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
eapol_version=1
fast_reauth=1

# Connecting to hidden SSIDs requires magic setting of ap_scan:
# Using MSI rt61 PCI card, ap_scan must be 1.
# Using EeePC rt2860, ap_scan must be 2.
# ap_scan=2

network={
  ssid="Your SSID here"
  scan_ssid=0
  key_mgmt=WPA-PSK
  pairwise=CCMP
  group=CCMP
  proto=WPA2
  psk= ... your key here ...
}

KB
Home