Netplan is a network configuration utility that is included in Ubuntu by default. It is used to manage the network configuration of a system, including the network interfaces, IP addresses, and DNS servers. In this article, we will look at Netplan in more detail and explain how to use it to configure a network on Ubuntu.
Here are some basic commands for using netplan:
# To apply the changes made to a netplan configuration file:
sudo netplan apply
# To generate network configuration files based on your netplan configuration:
sudo netplan generate
# To view the current network configuration:
sudo netplan --debug try
# To check the syntax of a netplan configuration file:
sudo netplan try
Note that the exact syntax and options for these commands may vary depending on your Linux distribution and version. For more information and a complete reference of the netplan commands, you can consult the netplan documentation or run the man netplan
command to view the manual pages.
This is how to enable the DHCP
To use Netplan, you will need to create a configuration file that specifies the desired network configuration. This file is typically called /etc/netplan/config.yaml
and has a specific format that defines the network interfaces, IP addresses, and other settings. For example, a simple configuration file might look like this:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
In this example, the configuration file specifies that the eth0
interface should be configured using DHCP. This means that the interface will automatically obtain an IP address, netmask, and other network settings from a DHCP server on the network.
Once you have created your configuration file, you can apply it to your system by running the netplan apply
command. This will apply the network configuration specified in the configuration file, and the changes will take effect immediately.
Here is how to configure a static IP address
To configure a static IP address using Netplan, you can specify the addresses
, gateway
, and nameservers
parameters in the configuration file. For example:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses: [192.168.0.100/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
In this example, the eth0
interface is configured with a static IP address of 192.168.0.100
, a netmask of 24
, and a default gateway of 192.168.0.1
. The nameservers
parameter specifies the IP addresses of the DNS servers that the interface should use.
Once you have edited the configuration file, you can apply the changes by running the netplan apply
command. This will apply the new network configuration, and the changes will take effect immediately. You can verify that the static IP address has been correctly configured by using the ip addr
command, which will print the IP address and other network settings for each interface.