Ubuntu 18.04 Bionic Beaver has switched to Netplan for configuring network interfaces. This is a yaml based configuration system, which should simplify the process.
This post will guide you through doing basic configurations, such as assigning a static IP or enabling DHCP on an interface.
Netplan Configuration File
Netplan is the new method of configuring Ubuntu network interfaces. While simple configuration, such as just setting a static IP, won’t gain much from the new system, a much more complex configuration will be greatly simplified.
The following is a list of the most common configuration options, and a description of how they are used.
Option | Example | Description |
---|---|---|
addresses | [192.168.1.2/24, 192.168.8.10/28] | A list of IP addresses to be assigned to an interface. The format uses CIDR notation. |
gateway4 | 192.168.1.1 | The IP address of your local IPv4 gateway. |
gateway6 | FDEC::1 | The address of your local IPv6 gateway. |
dhcp4 | true | Set whether DHCP is enabled for IPv4 – true of false |
dhcp6 | true | Set whether DHCP is enabled for IPv6 – true of false |
Configure Static IP Addresses
- Open the netplan configuration file into a text editor.
sudo vi /etc/netplan/50-cloud-init.yaml
- Modify the file to look similar to the following example.
network: ethernet: enp0s3: addresses: [192.168.1.10/24] gateway4: 192.168.1.1 nameservers: search: [lab, home] addresses: [8.8.8.8, 8.8.7.7] optional: true version: 2
- Save your changes and exit the text editor.
- It is good practice to validate your configuration before applying it, to prevent service disruption from invalid syntax.
sudo netplan try
- Apply your new settings by running the following command.
sudo netplan apply
Configuring DHCP
- Open the netplan configuration file into a text editor.
sudo vi /etc/netplan/50-cloud-init.yaml
- Modify the file to look similar to the following example.
network: ethernet: enp0s3: addresses: [] dhcp4: true optional: true version: 2
- Save your changes and exit the text editor.
- Apply your new settings by running the following command.
sudo netplan apply
- It is good practice to validate your configuration before applying it, to prevent service disruption from invalid syntax.
sudo netplan try
- Verify your network settings have been applied correctly.
sudo netplan ip leases enp0s3
- You should see something similar to the following.
# This is private data. Do not parse. ADDRESS=10.0.2.15 NETMASK=255.255.255.0 ROUTER=10.0.2.2 SERVER_ADDRESS=10.0.2.2 NEXT_SERVER=10.0.2.4 T1=43200 T2=75600 LIFETIME=86400 DNS=10.0.0.2 10.1.0.2 CLIENTID=ffe2343f3e00020000ab1167702761b1da338e