Skip to main content
In this lesson, you’ll learn how to configure network settings on an Ubuntu machine. We will explore network interfaces and addresses using the ip command and then apply permanent changes with Netplan. Detailed command outputs and sample configuration files are provided throughout.

Viewing Network Interfaces

The ip command displays comprehensive details about your network configuration. For example, running:
displays all the network interfaces on your system. Physical devices (such as Ethernet and wireless cards) and virtual interfaces are shown. The loopback interface (lo) is virtual and used for local communication (e.g., connecting to a database on 127.0.0.1), while an interface like enp0s3 represents a physical Ethernet adapter. To view IP addresses assigned to the interfaces, you can use either:
or the shorthand version:
A sample output may look like this:
Notice that the third interface (enp0s8) is marked as DOWN since it does not have an IP address assigned. You can also highlight important details of the output by using the -c (color) option. However, ensure that you place the -c option in the middle of the command. For example:
Here, the interface enp0s8 remains clearly marked as DOWN due to the absence of an IP address.

Activating an Interface

To activate an inactive interface (for example, enp0s8), run the following command:
This command performs the following steps:
  1. Specifies the link device.
  2. Uses the set parameter to configure a property.
  3. Identifies the device using dev.
  4. Applies the action of bringing the interface UP.
After executing the command and re-checking the IP addresses, the interface should be reported as UP and might receive an IPv6 address automatically. A typical session might look like:

Manually Adding IP Addresses

You can manually assign IP addresses to an interface. For example, to add an IPv4 address to enp0s8:
This command sets the IPv4 address 10.0.0.40 with a /24 subnet mask on enp0s8. Similarly, to add an IPv6 address, run:
After these commands are executed, running ip -c addr will confirm that the addresses have been added. Remember, an interface can have multiple IP addresses.

Removing IP Addresses and Deactivating an Interface

To remove an IP address (for example, an IPv6 address) and then bring the interface down, use the following commands:
Keep in mind that changes made using the ip command are temporary and will be lost upon reboot. The ip command is typically used for testing new configurations or troubleshooting existing settings.

Making Permanent Changes with Netplan

Permanent network configurations on Ubuntu Server are managed by Netplan. Netplan reads configuration files from the /etc/netplan directory and instructs lower-level networking services (such as systemd-networkd) to configure the system. To view the current Netplan configuration, run:
A sample output might be:
You can then list the configuration files in the Netplan directory with:
For example, you may see a file named 50-cloud-init.yaml. To view its contents, use:

Creating a New Netplan Configuration File

When configuring a different Ethernet device (such as enp0s8) with static IP settings, it’s a good practice to create a new configuration file. Files are processed in alphabetical order, so prefixing your file with a number like 99 ensures it is applied last. Here’s an example configuration:
Ensure you maintain proper indentation in YAML. The hyphen (-) indicates a list element; additional properties should be indented correctly. To apply the new configuration, you have two options. A safe method is to try the configuration first:
This command initiates a countdown and will revert the changes if you do not confirm by pressing ENTER before the timeout expires. You may also specify a shorter timeout using the --timeout option. If a mistake is made, press Ctrl+C to cancel.
If you see a warning like:Permissions for /etc/netplan/99-mysettings.yaml are too open. Netplan configuration should NOT be accessible by others.Then adjust the file permissions with:

Adding DNS Resolvers and Routes in Netplan

You can further customize your network settings in Netplan by adding DNS resolvers and network routes. Here’s an example configuration to set custom DNS servers for enp0s8 and define routes:
In this example, the nameservers block specifies Google’s public DNS servers. The routes block includes:
  • A specific route directing traffic for the 192.168.0.0/24 network via 10.0.0.100.
  • A default route directing all other traffic via 10.0.0.1.
Apply these settings using:
After confirmation, verify the network routes with:
You might see output similar to:
To check the configured DNS resolvers, run:
If you prefer setting global resolvers, edit /etc/systemd/resolved.conf by uncommenting the DNS line and adding your desired DNS addresses:
Then restart the resolver service:
Verify the updated global DNS configuration with:

Configuring Local Hostname Resolution

For local hostname resolution without relying on external DNS servers, update the /etc/hosts file. For example, to associate the hostname “dbserver” with the IP address 127.0.123.123, add the following line:
After saving the file, test the configuration with:
You should see output similar to:
To map a complex hostname (for testing purposes), for example directing “example.com” to 1.2.3.4, add:

Additional Tips and Resources

Netplan YAML files are designed for readability, but they require careful attention to format. If you need further assistance, consult the manual pages:
To search within the manual, use /address or /default routes and then press “n” to navigate through the results. Example configurations are also provided in /usr/share/doc/netplan/examples. Consider these examples:
  • DHCP Configuration Example:
  • Static Configuration Example:
You can list the contents of the documentation directory with:

Conclusion

In this lesson, you learned how to discover and modify network settings using the ip command and how to implement permanent changes with Netplan. Topics covered include configuring IPv4 and IPv6 addresses, setting DNS resolvers, defining custom network routes, and mapping hostnames locally via the /etc/hosts file. With these tools, you are well-equipped to troubleshoot and configure network interfaces on Ubuntu systems. Now, let’s jump ahead to the next lesson.

Watch Video