Set up Wireless with Different Profiles and WPA/WPA2 encryption (using /etc/network/interfaces)

Setup of WPA encrypted WiFi using a text file based configuration

You find the important information on how to set it up in the documentation of wpasupplicant:

zmore /usr/share/doc/wpasupplicant/README.modes.gz

For example if you want to connect to a WLAN named "WLAN-AF6432" with WPA security, you first have to get the encryption hash:

wpa_passphrase "WLAN-AF6432"

Enter your pre-shared key and press enter. This will get you:

network={
    ssid="WLAN-AF6432"
    #psk="secretKey"
    # adjust to your key:
    psk=2bfbbc0b096b47e300e3fdd210301
}

Add those lines to the end of /etc/wpa_supplicant/wpa_supplicant.conf:

network={
    ssid="WLAN-AF6432"
    scan_ssid=1 # only needed if your access point uses a hidden ssid
    #psk="secretKey"
    proto=WPA
    key_mgmt=WPA-PSK
    # adjust to your key:
    psk=be2bfbbc0b096b0e3fdd210301
}

Reload the configuration after the changes (assuming eth1 is your wlan interface):

sudo wpa_action eth1 stop
sudo wpa_action eth1 reload
sudo ifup eth1

Test the success of your settings:

sudo wpa_supplicant -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf -Dwext -w

If you get a message like CTRL-EVENT-CONNECTED - Connection to 00:12:bf:cf:f4:d7 completed , press [CTRL]-[C] to abort the test and everything is ready for the extended setup: Put the following lines to your /etc/network/interfaces.

auto lo
iface lo inet loopback
pre-up ifconfig eth1 up

# the roaming interface MUST use the manual inet method
iface eth1 inet manual
#wpa-driver wext #also for intel ipw2200!!!!
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf


# no id_str, 'default' is used as the fallback mapping target
iface default inet dhcp

## id_str="uni"
#iface uni inet dhcp

## id_str="home_static"
#iface home_static inet static
#   address 192.168.0.20
#   netmask 255.255.255.0
#   network 192.168.0.0
#   #broadcast 192.168.0.255
#   gateway 192.168.0.1

# connects with all unencrypted networks (with dhcp):
iface open inet dhcp

#Schnittstelle automatisch aktivieren
auto eth1

Then change the file /etc/wpa_supplicant/wpa_supplicant.conf:

network={
    ssid="WLAN-AF6432"
    #proto=WPA
    #key_mgmt=WPA-PSK
    ### no 'id_str' is given, /sbin/wpa_action will 'ifup default'
    # adjust to your key:
    psk=f2244d278203271b8e0e4daefae009585374a5d
}

network={
    ssid="wpk"
    ### no 'id_str' is given, /sbin/wpa_action will 'ifup default'
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP
    group=CCMP
    # adjust to your key:
    psk=f2244d278203271b8e0e4daefae009585374a5d
}

network={
    ssid="WLAN-AF6432wpk"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP
    group=CCMP
    # adjust to your key:
    psk=f2244d278203271b8e0e4daefae009585374a5d
}

# unverschl├╝sselte Netzwerke
network={
    ssid=""
    id_str="open"
    scan_ssid=1
    key_mgmt=NONE
}

You can configure multiple WLAN APs with different settings using this method.

More hints for using wpa_supplicant:

  • wpa_cli is the command line interface (CLI) of the WPA-supplicant
  • wpa_cli disconnect cut connection
  • wpa_cli reassociate get a new connection
  • wpa_cli status display informationen if a link is up and running or wich algorithms are used to secure the connection

resources

Comments