Best Netplan Configuration For Linux Network Interfaces

Table of Contents

Netplan has been the Ubuntu default Network Manager since Ubuntu version 18.04, often set during installation. Most VPS do not really require this because they are automatically networked. In a data center, though, you may see some interesting things. The netplan configuration files are written in YAML, which is straightforward to read. YAML was first used in 2001. Writing YAML can include some syntactical adjustment, but you can pick it up within the scope of this blog. The most interesting thing is that Netplan acts as a human-readable layer capable of transferring the configurations to the appropriate render. Making the experience nice and smooth.

You can network any Ubuntu server just like that, using nothing more than a terminal and an editor. For Ubuntu networking newbies, knowing this information is golden. Upgrading the information you ingest will only serve you in the future. So today we are going to look at a default configuration, set to auto-connect to Ethernet. Next we will set up an Ethernet configuration with a static IP. Then we will add Wi-Fi to this configuration. So, you should be able to set up your server. So, let’s get comfortable editing Netplan configurations. Now let’s keyboard cowboy up that network!

Default Netplan Configuration

Every time when installing a server you are often asked to input your network credentials. If you don’t, you will be given the default that allows plugging into any Ethernet cable. Making an efficient network configuration, indeed. Allowing local DHCP to control your address assignments with no other entries. Why not see for ourselves.

				
					vim /etc/netplan/00-installer-config.yaml

				
			
default netplan configuration
Netplan config

Now you can see how simple this configuration actually is, with only one boolean indicating we would like to use DHCPv4. We do not see a renderer option, so in this case the system is using NetworkD by default. This configuration is fine for at home, perhaps in a virtual machine. We can go ahead and close Vim for now by typing :q. This configuration is totally unrealistic anywhere that the public or an office environment may be concerned.

Local Ethernet

You will want to configure your server to function on a specific network for a few reasons. One reason is that you may want a static IP address, or rather one that will not change on you. If your IP continuously changes, you will be forced to look it up every time you want to SSH this server. Another reason is you may want to use a specific DHCP server that will assign your IPs in a way that you prefer. For example, a Pi Hole actually has DHCP as a feature. Let’s see what our interface name is, so we can add it to our configuration.

				
					ip a
				
			
ipa
Linux ip configuration

Now that we know our interface name “enp1so”, we can go ahead and assign it our YAML file. We will want to get the configuration file open again, this time with sudo so that we can edit the file.

				
					sudo vim /etc/netplan/00-installer-config.yaml

				
			

Now we will go ahead and edit our configuration, keeping in mind that we need to use our own device name IP addresses and choose our name servers. You can go ahead and type a to edit. You can use Ctrl c to copy and inside terminal or Vim, then you can use Ctrl Shift v to paste. Don’t worry about mistakes. You can always use Esc and type u to undo your last edit.

				
					network:
	version: 2
	renderer: NetworkManager
    ethernets:
       enp1so:
          dhcp4: false
          addresses: 10.0.2.15/24
          gateway: 10.0.2.7
          nameservers:
             addresses: [8.8.8.8, 8.8.4.4]
				
			
netplan updated configuration
Netplan static config

Notice here we decided to use Google for our name servers here. Just an easy external name server to use. The IP addresses and device name are pretty important to get right. They will enable or disable your network connection accordingly. We also specified that we wanted to use NetworManager as our renderer rather than NetworkD here. You should make sure to adjust these values as we suggested and go ahead and save the file by typing Esc, then type :wq. If you are just following along and do not want to save the configuration, type :q! to close the file without saving.

Complex Netplan Configurations

To get a Wi-Fi connection working with a server, you need to make sure you have the package wpasupplicant installed. It does not come installed automatically on a server, since using a server on Wi-Fi is more of an edge case. Assuming you have this package installed, you can proceed with Wi-Fi configurations.

				
					sudo vim /etc/netplan/00-installer-config.yaml

				
			

This configuration preserves the Ethernet configuration as well as provides a Wi-Fi connection, as seen below the “wifis:” line. This is so that you can run your edge server on a Wi-Fi network to reduce cabling. When you bring it back to your workshop, you can be sure that it will be at the correct IP when using SSH.

				
					network:
	version: 2
	renderer: NetworkManager
    ethernets:
       enp1so:
          dhcp4: false
          addresses: 10.0.2.15/24
          gateway: 10.0.2.7
          nameservers:
             addresses: [8.8.8.8, 8.8.4.4]
     wifis:
       wlan0:
           dhcp4: false
           addresses: 10.0.3.15/24
           gateway: 10.0.2.8
        access-points:
                  nameservers:
               addresses: [8.8.8.8, 8.8.4.4]
                   "your-network-SSID":
                     password: "your-password-here"
				
			
netplan config for wifi
Netplan wireless config

Notice, we had to find and use our Wi-Fi interface name, just like with the Ethernet interface name. We also do not want to have to guess the IP when using SSH over Wi-Fi. We also specified that we wanted to use NetworManager as our renderer rather than NetworkD here as well. Furthermore, we also will use a static IP configuration with DHCPv4 here as well. Next, you will notice the SSID (Service Set Identifier). You will need to know the network name or SSID. Then you will need to add your password in order to auto-connect once powered up. We can go ahead and save the file by typing Esc, then type :wq.

Finalization & Troubleshooting

Now we need to test out our configuration to see how well we did. See if they work. We can do this by using the built-in command option.

				
					sudo netplan try

				
			

This will give you a limited amount of time to try both connections. If they are both working well, we will want to finalize this configuration. Skip to debugging command if you run into trouble.

				
					sudo netplan apply

				
			

Now that we have finalized the configuration with Netplan, we need to tell Systemctl to start the service with the new configuration.

				
					sudo systemctl restart network-manager

				
			

Now, if you experience any issues, before you apply this configuration with Netplan you should do some troubleshooting.

				
					sudo netplan -d apply

				
			

The -d option allows for you to get a verbose printout that will help you debug the issues you may be having. You can always open your editor and check the configuration file to see if your IPs are correct. You may need to change an interface connection. Sometimes it is the network SSID or password. So be patient and remember that no one is perfect the first time. So get out there and connect your home office how you want! Make your network part of your home. Set up some edge servers and automate that home of yours. Bring in a media server like Plex. Set up an SFTP server for file storage or to help with local development. Perhaps you are a pin tester and need to red-team a hidden server into a data-center to phone home. We hope you found this information useful. Thanks for reading!

Meet the Author

Leave a Reply