Debian Linux Configure Wireless Networking With WPA2

I‘ve Atheros AR5001 wifi a/b/g card detected and supported natively under Linux. How do I configure my wireless card with WPA2 networking using /etc/network/interfaces file?

Wi-Fi Protected Access II (WPA2 i.e. IEEE 802.11i) is security protocols for wireless communication. It introduces CCMP, a new AES-based encryption mode with strong security in mind. Under Debian Linux you need to install wpasupplicant to support for WPA and WPA2 networks. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands as root user:

Step #1: Install wpasupplicant

To install wpasupplicant simply type the following command as root user:
# apt-get install wireless-tools
# apt-get install wpasupplicant

Step #2: Verify WiFi / Wireless Card Is Detected

Use the lspci command to verify that card is detected:
# lspci
# lspci | grep -i wlan
# lspci | grep -i wireless
# lspci | grep -i wifi
# lspci -nn | grep Network

Sample outputs:

0c:00.0 Network controller: Intel Corporation Ultimate N WiFi Link 5300

This page explains the lspci command to find out Wireless driver chipset information under Linux. Or you can go to Linux wireless LAN support page and make sure your card is listed as supported device under Linux. You can also see your wireless interface name using the following command:
# ifconfig -a
# dmesg | grep -i wlan
# dmesg | grep -i wireless

Step #3: Configure WPA2

Edit /etc/network/interfaces file, enter:
# vi /etc/network/interfaces
Setup wlan0 with the SSID and PSK as follows:

auto wlan0
iface wlan0 inet dhcp
    wpa-ssid YOUR-SSID-HERE

Make sure you use strong pass-phrase. Save and close the file. You can now connect to the interface, enter:
# ifup wlan0
# ifconfig wlan0
# ping router-ip-here
# ping

OR you can restart the networking service using any one of the following method:
# /etc/init.d/networking restart
# service networking restart

Get Info About Your Network

To see more info about wifi, enter:
# iwconfig wlan0

Scan Your Wireless Network

Type the following command:
# iwlist wlan0 scan

Sample /etc/network/interface Config File

# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
# The wireless network interface with dhcp
auto wlan0
iface wlan0 inet dhcp
    wpa-ssid nixcraft
    wpa-key-mgmt WPA-PSK
    wpa-group TKIP CCMP

Troubleshooting wpa_supplicant

See wpa_supplicant log file /var/log/wpa_supplicant.*.log using the tail, more, or grep command:
# tail -f /var/log/wpa_supplicant.wlan0.log
# grep 'something' /var/log/wpa_supplicant.wlan0.log

A Note About GUI Configuration Tool

You can use NetworkManager – a graphical interfaces for GNOME and KDE. If you are using NetworkManager, avoid using Debian’s /etc/network/interfaces file. See this page for more information about Gnome / KDE wireless network config tool.

Recommended readings:

Anytime you need assistance with Linux wifi configuration option, turn to the following man page first. It will give you detailed information, parameters and switches for wifi configurations. For example, man 5 interfaces opens the man page for the interfaces network configuration file:
$ man 5 interfaces
$ man 8 wpa_supplicant
$ man 8 iwconfig
$ man 8 iwlist

See how to use apt-get command to install packages under Linux.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 17 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
17 comments… add one
  • Alex Apr 6, 2011 @ 22:01

    Thank you very much.
    It’s helped for me on Debian 6.0.1 Squeeze.

  • Mr.Mac Oct 3, 2011 @ 20:12

    Thanks for the nice tut!

    I used it w. Debian 6 squeeze w. an old Mac Min who has a

    root@macmini:~# lspci | grep -i wireless
    02:00.0 Ethernet controller: Atheros Communications Inc. AR5001 Wireless Network Adapter (rev 01)

    I chose a static IP:

    root@macmini:~# cat /etc/network/interfaces
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    # The loopback network interface
    auto lo
    iface lo inet loopback
    # The primary network interface
    allow-hotplug eth0
    iface eth0 inet static
    	# dns-* options are implemented by the resolvconf package, if installed
    auto wlan0
    iface wlan0 inet static
            wpa-ssid ***hidden***
            wpa-psk ***hidden***
            # dns-* options are implemented by the resolvconf package, if
            # installed

    everything works fine, BUT…:

    When I unplug the ethernet cable, the wireless connection vanishes.
    Why is this so and how can I prevent it from happening? :)

    Cheers! :)

    • DG Oct 15, 2014 @ 21:08

      Great article – thanks for the help!

  • Wizzy Apr 14, 2012 @ 9:12

    It is static solution and today world is dynamic. It is rather most awkward solution I ever have seen. Use Network Manager instead. It would remember password and they won’t be stored in plain text. What is the point for WPA/RSN (there no such thing as WPA2, standard do not specify any WPA1 nor WPA2 – just WPA and RSN and coding standards TKIP and CCMP), if you would provide password for potential cracker in plain text?

  • Gandur May 8, 2012 @ 20:08

    Lol…isn’t it possible to etablish wlan WPA2 with static configuration?

    The statis config was also the problem why my network wasn’t working. I have to enable the dhcpd on the router an open crackers a door more?! ;)

  • neonsignal Jun 1, 2012 @ 12:23

    An alternative to storing the WPA SSID and passphrase in the /etc/network/interfaces file is to store them in /etc/wpa_supplicant/wpa_supplicant.conf. The advantage of this is that the passphrases are not readable to non-root users.

    The wpa_supplicant.conf is not as simple in format; but a stanza can be generated by using the wpa_passphrase tool:

    wpa_passphrase ssid key >>/etc/wpa_supplicant/wpa_supplicant.conf

    You then need to add a line to the /etc/network/interfaces iface stanza so that it knows where it find the configuration:

    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

    There are, of course, options for using WPA2 and setting any other parameters.

  • Gandur Jun 3, 2012 @ 10:25

    The network-manager of ubuntu disallowed me to configure wlan with static addresses. After a deinstallation of it and a reboot works my wlan with static configuration perfect.

  • Nick Jun 13, 2012 @ 19:13

    Awesome article that really helped me. Stupid question, how would you enter an ssid that’s multiple words? My ssid was “Nick’s Network” and I entered: wpa-ssid “Nick’s Network” and it refuse to obtain an IP. In desperation I changed the ssid on the router to Nick and now it works fine. What was I doing wrong?

    • 🐧 nixCraft Aug 23, 2012 @ 14:23

      It should work:

      wpa-ssid "YOUR SSD HERE"

      It is possible that ‘ an apostrophe may have caused the problem.

  • Rondinelli Dec 13, 2013 @ 1:24

    Thank you! Works very well!! :)

  • Konrad Iturbe Jul 18, 2014 @ 20:01

    /etc/network/interfaces is a readonly file that cannot be modified using vi, gedit or anything.

  • Nick Aug 18, 2014 @ 4:02

    Do you not have root capability?

  • Cypher Aug 6, 2015 @ 0:33

    Thank you so much! This worked like a charm :)

  • Ricardo Barioni Jan 5, 2016 @ 22:41

    Just perfect!

  • Susan Mar 24, 2016 @ 2:21

    Thanks for helping me out — Debian 8 and Nvidia card = command line only. Much easier to get proper drivers when you have wireless!

  • andrew May 26, 2017 @ 13:54

    Didn’t work. I can’t get any linux cli wifi tool to work properly! netctl gives random errors, ifup doesn’t give give me an ip, iwconfig option for plaintext keys`key s:` returns an error.

    This sucks.

  • Jvek Jun 5, 2017 @ 19:11

    ifup wlan0
    wpa_supplicant: /sbin/wpa_supplicant daemon failed to start
    run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
    ifup: failed to bring up wlan0

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum