Updated: Nov. 5, 2023 Updated to correct the .yaml used in the Ubuntu example, the previous version did not have the proper indentation for the example presented.

Note: When adjusting network settings on Ubuntu Server using Netplan, be careful if you are acessing that server using ssh since changing it might lock up your connection via SSH.

As I am familiarizing myself with new technologies, including virtualization using Proxmox, I began to experiment with various Linux virtual machines and after their setup was complete I wanted to set a static IP address so that I would be able to regularly access the virtual machine using a remote access tool like SSH. I had come across several guides on YouTube, Ask Ubuntu, and the Ubuntu Forums that proposed solutions which relied on adjusting the configuration files for a Ubuntu-specific tool called NetPlan. Unfortunately I was unsuccessful with setting up a static IP address with the resources I came across - I was able to setup a static IP address, but I would not be able to connect to the Internet.

I had almost given up all hope when I came across one final video that suggested a solution which also used NetPlan. I am not certain what it was about the video, but it had similar steps as the previous resources, however this time I was able to succeed. In light of this success I wanted to share my findings for Ubuntu which you can find below and for instructions for Debian they are at the bottom:

Ubuntu 20.04 and newer

Open Terminal and run the following command:

ip -brief address

This command will print out a table with 3 columns of data, the name of the network device, the status, and the IP address - depending on the setup it might include your IP address with the common version 4 format and version 6, for the purposes of this guide we can ignore the IP version 6 address.

In my case I worked exclusively with a wired network connection, however I imagine this should work for a wireless connection as well.

The name of the wired connection that you will want to be concern with will start with an e for Ethernet and w for Wireless, for example eth0 and wlan0. You will want to note the name of the device.

cd /etc/netplan
ls *.yaml

When using the ls command you may be presented with multiple files with the file extenstion .yaml, in this case it would be a good idea to read the contents of the file by using the cat command:

cat 01-network-config.yaml

If the file contains a line that says ethernets then it means this configuration is for an Ethernet connection and if it says wifis or *wireless then it means that it is for a Wireless connection. Once you have decided on which configuration file to edit I would recommend that you make a backup of the original configuration, as it is a configuration file it would be wise to use the sudo command:

sudo cp 01-network-config.yaml 01-network-config.yaml.old

With a backup we can simply overwrite the new version by copying the old version on the new - sudo cp 01-network-config.yaml.old 01-network-config.yaml. We can now edit the file using your favourite text editor, in my case I use nano:

sudo nano 01-network-config.yaml

You can remove the contents of the file and paste the below, modifying the addresses to match your network’s IP addresses and netmask.

# This is the network config written by 'subiquity'
network:
  ethernets:
    # network name
    eth0:
      dhcp4: false
      addresses: 
          - #.#.#.#/24
      routes:
          - to: default
            via: #.#.#.#
      nameservers:
          addresses: [#.#.#.#]
version: 2

In the above I have bolded the areas where you will need to enter your own data and will discuss details below:

eth0 This is the name of the Ethernet device we got from the ip command from earlier.

address: This is the static IP address you will set, the /24 portion is necessary at the end.

via: This is the gateway for your network, in a home network environment this will be the IP address of your router.

nameservers addresses: This may differ if you are using a DNS service from Google, Linode, or some other service. If you are not using such a service then entering the gateway is sufficient.

Once you have completed the modifications you will then run: sudo netplan apply1 to apply the changes, note that if you are connected to the computer via SSH this will disrupt your connection. Finally you may receive messages about the configuration file’s permission, to alleviate these error messages you can adjust the permissions of the configuration file so that only the owner of the file (that being you) will be able to change it using chmod 600 01-network-config.yaml

Debian 11 and newer

In setting up my Proxmox server on an old laptop I couldn’t install Proxmox directly with their ISO, but instead had to install Debian first, prepare it for Proxmox, and finally install Proxmox. Shortly after this experience Debian released Debian 12 and I decided to go through the setup process once more with Debian. I learned very quickly that although Ubuntu is based on Debian, they are similar in a lot of ways (they both use apt for install software and use .deb files), but also differ in that Debian does not appear to use many (if any!) tools that were created for Ubuntu specifically, such as Netplan, and as such the process to create a static IP address is a little different.

Thanks to this brilliant video from Jack Wallen (writer for TechRepbulic) the process to setup a static IP address becomes as simple as breathing.

Open Terminal and run the following command:

ip -brief address

As in the instructions for Ubuntu make sure to copy the name of your network device:

cd /etc/network/
sudo cp interfaces interfaces.old
sudo nano interfaces

Either remove the text under the The primary network interface section or comment out the line by putting a ‘#’ at the beginning of the line, for example: # iface eth0 auto.

Enter the following text:

auto eth0
iface eth0 inet static
  address #.#.#.#
  netmask #.#.#.#
  gateway #.#.#.#
  dns-nameservers #.#.#.#

eth0: This is the name of the Ethernet device we got from the ip command from earlier.

address: This is the static IP address you will set, unlike with in Ubuntu you just enter the IP address.

netmask: This is the netmask for your network, the default subnet mask is 255.255.255.0 which is what I enter in this field as per Jack’s instructions.

gateway: This is the gateway for your network, in a home network environment this will be the IP address of your router.

dns-nameservers: This may differ if you are using a DNS service from Google, Linode, or some other service. If you are not using such a service then entering the gateway is sufficient.


  1. On the Netplan website there are other commands that can be run to test that the configuration works, you can see the details on the site if you would like to test the settings before applying them.  ↩︎