Linux/Wifi

Common Tasks
Wireless interface tools: ifconfig # set interface ip address and up/down state iwconfig # configure wireless settings (SSID, key, mode) iwlist   # scan wireless dhclient # dhcp client

Set ESSID: iwconfig [interface] essid [essid] iwconfig eth1 essid toast

Set managed mode: iwconfig eth1 mode Managed
 * 1) note: interface may need to be down to change (ifconfig eth1 down)

Set WEP key: iwconfig eth1 key 0123-4567-89 iwconfig eth1 key off

WPA: wpa_passphrase [SSID] >> /etc/wpa_supplicant/wpa_supplicant.conf network={ ssid="testnetwork" #psk="testpassword" psk=ed5b87ba31bf9d6611576f94c57e848696005ea2d5743baab976a48ed11d1b2a }
 * 1) type password, hit enter

wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlan0 -D madwifi wpa_supplicant -c wpa.conf -i wlan0 -d
 * 1) start wpa_supplicant daemon
 * 1) debug mode:

DHCP client: dhclient [interface] # get DHCP address dhclient -r [interface] # release DHCP address dhclient [interface] -H [hostname] # get DHCP address and set hostname

Other examples: iwconfig wlan0 mode managed iwpriv wlan0 set AuthMode=WPAPSK iwpriv wlan0 set EncrypType=TKIP iwpriv wlan0 set WPAPSK="AP's wpa-preshared key" iwconfig wlan0 essid "AP's SSID"

Scan: iwlist [interface] scan

Common wireless interfaces: eth1, wlan0, ath0

madwifi
See madwifi

Wireless WEP Authentication
Shared WEP key: iwconfig ath0 key iwpriv ath0 authmode 2 iwpriv ath0 authmode 1
 * 1) operating in a restricted, shared-key environment
 * 1) operating in open system key (which is often considered more secure)

Connecting to AP
Connecting to an open AP: iwconfig ath0 essid "eddie" iwconfig ath0 ap 00:06:25:E8:3A:05

Connect to first available open AP: iwconfig ath0 ap any iwconfig ath0 ap auto

Connecting with DHCP
DHCP Connection: dhclient ath0 dhcpcd ath0

Connect without DHCP
ifconfig ath0  netmask up route add default gw route add default gw  vi /etc/resolv.conf search t0e.org nameserver 10.10.10.1

CentOS interface setup
/etc/sysconfig/network-scripts/ifcfg-ath0 DEVICE=ath0 BOOTPROTO=dhcp HWADDR=00:0F:20:95:6A:9A ONBOOT=no DHCP_HOSTNAME=kencent

Ubuntu interface setup
/etc/network/interfaces: iface lo inet loopback auto lo

iface eth0 inet dhcp

iface wlan0 inet manual allow-hotplug wlan0 wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp

Connecting to an AP with WEP
using shared WEP key: iwpriv ath0 authmode 2

using open WEP key (which is often considered more secure): iwpriv ath0 authmode 1

Specify WEP key: iwconfig ath0 key  iwconfig ath0 key 

Connecting to an AP with WPA
Make PSK: wpa_passphrase My_WPA_Protected_AP_ESSID "Some_Decent_PassPhrase_of_up_64_Characters" >> /etc/wpa_supplicant.conf

Edit /etc/wpa_supplicant.conf and add the lines into the network section created above: key_mgmt=WPA-PSK proto=RSN
 * 1)    proto=WPA

Uncomment the proto=WPA line (and comment out the RSN line) to enable WPA. Leave as is for WPA2 (stronger encryption).

Secure: chmod 640 /etc/wpa_supplicant.conf

Full example: modprobe ath_pci # if running pre-r1408 Madwifi code, then also: wlanconfig ath0 create wlandev wifi0 wlanmode sta iwconfig ath0 essid "My_WPA_Protected_AP_ESSID" ifconfig ath0 192.168.0.100 up /usr/local/bin/wpa_supplicant -dd -Dmadwifi -iath0 -c/etc/wpa_supplicant.conf

See if connected: iwconfig ath0

Automate wpa_supplicant: modprobe ath_pci (If running pre-r1408 Madwifi code, then also: wlanconfig ath0 create wlandev wifi0 wlanmode sta) iwconfig ath0 essid "My_WPA_Protected_AP_ESSID" ifconfig ath0 192.168.0.100 up wpa_supplicant -Bw -Dmadwifi -iath0 -c/etc/wpa_supplicant.conf
 * 1) !/bin/sh

old note: wpa_supplicant -Bw -Dwext -iath0 -c/etc/wpa_supplicant.conf wpa_supplicant -Bw -Dmadwifi -iath0 -c/etc/wpa_supplicant.conf
 * 1) if you are using a Linux version smaller than 2.6.14

References:
 * UserDocs/WPA_PSK_on_Both_Ends - madwifi.org - Trac

wifi init.d

 * 1) !/bin/sh
 * 2) chkconfig: - 99 01
 * 3) description: Starts and stops the Wireless
 * 4) lock:    /var/run/wifi
 * 5) config:  /etc/sysconfig/wifi
 * 6) config:  /etc/wpa_supplicant.conf
 * 1) config:  /etc/sysconfig/wifi
 * 2) config:  /etc/wpa_supplicant.conf

if [ -f /etc/init.d/functions ] ; then . /etc/init.d/functions elif [ -f /etc/rc.d/init.d/functions ] ; then . /etc/rc.d/init.d/functions else exit 1 fi
 * 1) Source function library.

if [ ! -e /etc/sysconfig/wifi ] ; then echo "ERROR: /etc/sysconfig/wifi is missing" exit 1 else . /etc/sysconfig/wifi fi
 * 1) /etc/sysconfig/wifi
 * 2) WIFI_SSID=ssid
 * 3) WIFI_DHCP=yes
 * 4) WIFI_AUTH=wpa|wep


 * 1) WPA
 * 2) wpa_passphrase "My_WPA_Protected_AP_ESSID" "Some_Decent_PassPhrase_of_up_64_Characters" >> /etc/wpa_supplicant.conf

LOCKFILE=/var/run/wifi

case "$1" in start)    echo -n "Starting wifi: "    if [ -e $LOCKFILE ] ; then      echo -n "Wifi already running"      failure ; echo ; exit 1    fi    touch $LOCKFILE    modprobe ath_pci    iwconfig ath0 essid "${WIFI_SSID}"    if [ "${WIFI_AUTH}" = "wpa" ] ; then      wpa_supplicant -Bw -Dmadwifi -iath0 -c/etc/wpa_supplicant.conf    else      echo -n "code not written yet!"      failure ; echo ; exit 1    fi    if [ "${WIFI_DHCP}" = "yes" ] ; then      dhclient ath0 &> /dev/null      if [ "$?" != "0" ] ; then        echo -n "unable to obtain ip address!"        failure ; echo ; exit 1      fi    else      echo "code not written yet!"      failure ; echo ; exit 1    fi    success ; echo ; exit 0    ;;  stop) echo -n "Stopping wifi:" rm -f $LOCKFILE dhclient -r ath0 &>/dev/null killall wpa_supplicant &>/dev/null modprobe -r ath_pci success ; echo ; exit 0 ;; restart)        $0 stop        $0 start        ;;  status) if [ -e $LOCKFILE ] ; then echo "Wifi is running" exit 1 else echo "Wifi is stopped" exit 1 fi   ;; *)   echo $"Usage: $0 {start|stop|restart|status}"    exit 2 esac

WPA with Linux
wpa_passphrase YOURSSID yourpassphrase > /etc/wpa_supplicant.conf chmod 640 /etc/wpa_supplicant.conf wpa_supplicant -Bw -Dwext -iath0 -c/etc/wpa_supplicant.conf
 * 1) or use -Dmadwifi instead of -Dwext

References:
 * Connecting to an AP with WPA
 * Setting up a Client Using WPA-PSK
 * WPA on madwifi: AP & Station