Software & AppsOperating SystemLinux

How To Assign an IP Address in Ubuntu Server 20.04.3 Using Command Line

Ubuntu 7

In this guide, we will walk through the process of assigning an IP address in Ubuntu Server 20.04.3 using the command line. This is often necessary for setting up servers or network-related applications.

Quick Answer

To assign an IP address in Ubuntu Server 20.04.3 using the command line, you can use the Netplan configuration utility. Open the Netplan configuration file, modify the network interface settings to specify a static IP address, gateway, and DNS servers, save the changes, and apply the new configuration using the sudo netplan apply command. Verify the assigned IP address using the ip addr show command.

Introduction to Netplan

Starting from Ubuntu 17.10, the /etc/network/interfaces file is no longer used by default. Instead, Ubuntu now uses Netplan, a new command-line network configuration utility, to manage and configure network settings easily in Ubuntu systems.

Netplan reads network configuration from /etc/netplan/, where you can store .yaml files. It is more powerful and flexible than the old method and allows for more complex configurations.

Accessing the Netplan Configuration File

To assign an IP address, you need to edit the Netplan configuration file. Here’s how you can do it:

  1. Open the terminal.
  2. Type the following command to open the Netplan configuration file using the nano text editor:
sudo nano /etc/netplan/00-installer-config.yaml

Note: The filename may vary depending on your system.

This command uses sudo for administrative privileges, nano as the text editor, and /etc/netplan/00-installer-config.yaml is the location and name of the Netplan configuration file.

Configuring the IP Address

Inside the file, you will see a YAML structure similar to the following:

# This is the network config written by 'subiquity'
network:
 ethernets:
 ens18:
 dhcp4: true
 version: 2

In this example, the network interface ens18 is set to use DHCP (Dynamic Host Configuration Protocol), which means the IP address is automatically obtained from the DHCP server.

To assign a static IP address, modify the configuration to something like this:

# This is the network config written by 'subiquity'
network:
 ethernets:
 ens18:
 addresses: [192.168.1.100/24]
 gateway4: 192.168.1.1
 nameservers:
 addresses: [8.8.8.8, 8.8.4.4]
 version: 2

In this configuration:

  • ens18 is the name of your network interface. Replace it with your network interface name.
  • addresses specifies the static IP address and subnet mask (e.g., /24 for a 24-bit subnet).
  • gateway4 specifies the IP address of the gateway (router).
  • nameservers specifies the IP addresses of the DNS servers.

Applying the Configuration

After editing the configuration, save the changes and exit the text editor. To save and exit in nano, press Ctrl+X, then Y, then Enter.

Finally, apply the new configuration by running the following command:

sudo netplan apply

This command will apply the changes you made to the configuration file.

Verifying the IP Address

After applying the Netplan configuration, your network interface should have the assigned static IP address. You can verify it by running the ip addr show command:

ip addr show

This command will display the network configuration of all network interfaces. Look for your interface and check if the IP address is correctly assigned.

Conclusion

Assigning an IP address in Ubuntu Server 20.04.3 using the command line can seem complex at first, but once you understand the structure of the Netplan configuration file, the process becomes straightforward. Remember to adjust the configuration according to your network setup. If you encounter any issues, make sure to check the Netplan documentation or seek further assistance.

What is Netplan?

Netplan is a command-line network configuration utility used in Ubuntu systems to manage and configure network settings easily. It reads network configuration from /etc/netplan/ and allows for more complex configurations compared to the previous method using the /etc/network/interfaces file.

How do I access the Netplan configuration file?

To access the Netplan configuration file, open the terminal and type the following command: sudo nano /etc/netplan/00-installer-config.yaml. This command opens the Netplan configuration file using the nano text editor. Please note that the filename may vary depending on your system.

How do I assign a static IP address using Netplan?

To assign a static IP address using Netplan, you need to modify the Netplan configuration file. Inside the file, locate the YAML structure for your network interface and modify it to include the desired static IP address, subnet mask, gateway, and DNS servers. Save the changes and apply the configuration using the sudo netplan apply command.

How can I verify if the IP address is correctly assigned?

After applying the Netplan configuration, you can verify if the IP address is correctly assigned by running the ip addr show command in the terminal. This command will display the network configuration of all network interfaces. Look for your interface and check if the IP address is correctly assigned.

Where can I find further assistance or documentation on Netplan?

If you encounter any issues or need further assistance, you can refer to the Netplan documentation. It provides detailed information on various configuration options and troubleshooting steps.

Leave a Comment

Your email address will not be published. Required fields are marked *