In this tutorial you will learn how to connect to WiFi from command line using Netplan. This could be useful if you are running a headless Ubuntu 20.04 system such as server or Ubuntu 20.04 on Raspberry Pi.

In this tutorial you will learn:
  • How to identify the name of your wireless network interface
  • How to configure Netplan to connect to wireless network (SSID)
Ubuntu 20.04: Connect to wifi from command line with Netplan
Ubuntu 20.04: Connect to wifi from command line with Netplan

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
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

Ubuntu 20.04: Connect to WiFi from command line with Netplan step by step instructions

  1. First step is to identify the name of your wireless network interface. To do so execute:
    $ ls /sys/class/net
    enp0s25  lo  wlp3s0
    
    Depending on your Ubuntu 20.04 system the wireless network interface name would be something like: wlan0 or like in this case it is wlp3s0.
  2. Next, navigate to the /etc/netplan directory and locate the appropriate Netplan configuration files. The configuration file might have a name such as 01-network-manager-all.yaml or 50-cloud-init.yaml.
    $ ls /etc/netplan/
    

  3. SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  4. Edit the Netplan configuration file:
    $ sudoedit /etc/netplan/50-cloud-init.yaml
    
    and insert the following configuration stanza while replacing the SSID-NAME-HERE and PASSWORD-HERE with your SSID network name and password:
        wifis:
            wlan0:
                optional: true
                access-points:
                    "SSID-NAME-HERE":
                        password: "PASSWORD-HERE"
                dhcp4: true
    
    Make sure that the wifis block is aligned with the above ethernets or version block if present. The entire configuration file may look similar to the one below:
    # This file is generated from information provided by the datasource.  Changes
    # to it will not persist across an instance reboot.  To disable cloud-init's
    # network configuration capabilities, write a file
    # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
    # network: {config: disabled}
    network:
        ethernets:
            eth0:
                dhcp4: true
                optional: true
        version: 2
        wifis:
            wlp3s0:
                optional: true
                access-points:
                    "SSID-NAME-HERE":
                        password: "PASSWORD-HERE"
                dhcp4: true
    
    Alternatively, you may also wish to configure a static IP address to your wireless interface.
  5. Once ready, apply the changes and connect to your wireless interface by executing the bellow command:
    $ sudo netplan apply
    
    Alternatively, if you run into some issues execute:
    $ sudo netplan --debug apply
    
  6. If all went well you would be able to see your wireless adapter connected to the wireless network by executing the ip command:
    $ ip a
    
FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions