/etc/network/interfaces to connect Ubuntu to a wireless network

If you want to connect to a wireless network on Ubuntu or any other Debian based Linux distro, one of the many ways to do it is by editing the /etc/network/interfaces file with your Wi-Fi network info.

This is a command line only method, so it’s very useful if you don’t have a GUI installed on the system but need to get on to the WiFi network. It will also support DHCP or static configuration. Read on to see how to connect to a wireless network by editing this file.

In this tutorial you will learn:

  • Connect to wireless network via /etc/network/interfaces file
Editing the interfaces file to connect to a wireless network

Editing the interfaces file to connect to a wireless network
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Debian based distros
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Edit /etc/network/interfaces file

  1. Start by finding the name of your wireless network interface. A simple ip a command should do the trick. The output will most likely show your Wi-Fi interface as wlan0, wlp3s0, or something similar.
  2. Next, edit your system’s /etc/network/interfaces file and append the following lines to use DHCP. Even if the file doesn’t already exist on your system, you can create it and it will be read by the network manager.
    auto wlan0
    iface wlan0 inet dhcp
    wpa-essid mywifiname
    wpa-psk mypass

    Be sure to replace wlan0 with the name of your own wireless interface, and substitute your own Wi-Fi’s name (ESSID) and password where we’ve put our examples.

  3. Alternatively, you can copy and paste the following example and substitute your own values if you wish to use a static IP configuration.
    auto wlan0
    iface wlan0 inet static
    wpa-essid mywifiname
    wpa-psk mypass
  4. To make the changes take effect, it’s best to completely restart the system.
    $ sudo reboot

That’s all there is to it. If you configured everything correctly, your interface should connect automatically to the wireless network upon future reboots.