Document Scope
This guide covers some basic steps for managing your network in current (18.04 and later) versions of Ubuntu using the newer "Netplan" style of interface configuration. Managing network interfaces is an essential step in keeping your server accessible to the Internet for remote access, updates, etc. These are just some of the basic steps for network management and for a deeper dive you can refer to the Ubuntu wiki for Command Line Network Configuration.
Prerequisites
Please note this guide only applies to Ubuntu systems using the newer method of managing network, via Netplan. Systems using Netplan cannot manage the network via GUI but instead rely on YAML files.
Please note all of the below code snippets and commands are for example purposes only. These were taken from an Ubuntu virtual machine running in Virtual Box. Your specific files/paths may be slightly different and you should take care to not simply copy/paste and expect things to work exactly the same.
What is Netplan?
Introduced back in Ubuntu 18.04, networking was redone using a new system from Canonical called Netplan – a YAML based configuration network configuration system for NetworkManager and systemd.
NetPlan Files
Netplan uses a filetype called YAML files to configure network interfaces. These files can all be found by default in the directory /etc/netplan. The default file networking interfaces for a new Ubuntu 22.04 install is:
/etc/netplan/00-installer-config.yaml
To edit the default netplan file, use the following command.
sudo vi /etc/netplan/00-installer-config.yaml
Alternatively, a simpler text editor by the name of nano can be used instead of vim.
sudo nano /etc/netplan/00-install-config.yaml
This default file is based on how the Ubuntu installer detected/configured your network connection during installation. The Ubuntu VM created for this guide has the following default Netplan YAML:
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
dhcp4: true
version: 2
Configuring Your Interface
Netplan has a large variety of options that you can use to get VERY specific with how your interfaces are configured and operate. We will not be providing a fully comprehensive list of how to use Netplan as this guide is just to provide a basic guide to getting your interface operational using a couple traditional methods (DHCP and static IP).
Step 1: List Available Network Interfaces
Run “ip link show” without quotes to display a list of network interfaces, including Ethernet ports. You can identify Ethernet ports like eth0, eth1, etc.). In this example, the ethernet is interface is enp0s3.
exx@exx:~$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:f0:60:92 brd ff:ff:ff:ff:ff:ff
exx@exx:~$
Step 2: Edit the interfaces file
Using your preferred editor, edit your YAML file. A basic file using DHCP for IPv4 and IPv6 would look something like this:
# This example YAML file sets up DHCP addressing for both IPv4 AND IPv6 on ethernet
# interface enp0s3
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: true
dhcp6: true
Or for a static IP configuration:
# This example YAML file sets up a static IP for both IPv4 AND IPv6 on ethernet
# interface enp0s3
network:
version: 2
renderer: networkd
ethernets:
en01:
addresses:
- 192.168.1.25/24
- "2001:1::1/64"
gateway4: 192.168.1.1
gateway6: "2001:1::2"
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Step 3: Apply the Netplan config
To apply your changes, simply run the below command.
sudo netplan apply
Wrap-Up
Above are just two examples of how to configure an ethernet interface in Ubuntu 18.04 and later. For FAR more examples you can visit the Netplan How-To Guide where you will also find all of the documentation on how to fully make use of this new methodology for network configuration in Ubuntu.
Comments
0 comments
Please sign in to leave a comment.