WindowsMacSoftwareSettingsSecurityProductivityLinuxAndroidPerformanceConfigurationApple All

How to Configure a Static IP on Ubuntu Server

Edited 4 weeks ago by ExtremeHow Editorial Team

Static IPUbuntuServerNetworkingLinuxConfigurationIP AddressSystemServer ManagementOperating Systems

How to Configure a Static IP on Ubuntu Server

This content is available in 7 different language

In the field of networking, assigning a static IP address to your Ubuntu server is an important task. Configuring a static IP ensures that the server's IP address does not change over time. This can be important for servers that host websites, databases, or services that need to be constantly accessed by users or other network devices. In this detailed guide, we will walk through the steps required to assign a static IP address to Ubuntu server.

Understanding IP addresses

Before we proceed with the steps, it would be useful to understand what an IP address is. An IP (Internet Protocol) address is a unique address that is assigned to every device connected to a network. This address allows the device to communicate with other devices on the network. An IP address can be assigned dynamically by DHCP (Dynamic Host Configuration Protocol) or manually as a static address.

Static vs dynamic IP address

A dynamic IP address is automatically assigned by the DHCP server whenever a device connects to the network. This is convenient for general use, but not ideal when you want to ensure that the server's address is always the same. On the other hand, a static IP address is manually configured and remains constant unless it is manually changed. Configuring a static IP for your server can improve network reliability and accessibility.

Prerequisites

Before proceeding with the configuration, ensure that the following prerequisites are met:

Steps to configure static IP

Follow the steps below to configure static IP on Ubuntu Server:

Step 1: Check the current network settings

Before making any changes, it is advisable to check the existing network configuration. You can get information about the interfaces available on the server using the following command:

$ ip addr show

This command will display a detailed list of network interfaces with their current configuration.

Step 2: Identify the network interface

Identify the network interface you want to configure. The interface is usually named eth0, ens33, or something similar. Note the current DHCP-enabled IP address and interface name for reference.

Step 3: Edit the Netplan configuration

Ubuntu uses Netplan for network configuration. You must edit the Netplan configuration file. This file is typically located in the /etc/netplan/ directory. Use your favorite text editor to open the file (for example, 01-netcfg.yaml or 50-cloud-init.yaml).

For example, you can use the nano editor with this command:

$ sudo nano /etc/netplan/01-netcfg.yaml

Step 4: Modify the configuration file

In the configuration file, you will define a static IP. Here is a basic example of what the configuration might look like:

network: version: 2 ethernets: ens33: dhcp4: no addresses: - 192.168.1.10/24 gateway4: 192.168.1.1 nameservers: addresses: - 8.8.8.8 - 8.8.4.4

In this example, replace ens33 with your network interface name, and provide the desired IP address, subnet mask (/24 for a subnet mask of 255.255.255.0), gateway, and DNS server.

Step 5: Apply the configuration

After making changes to the configuration file, apply the settings using the following command:

$ sudo netplan apply

This command will apply the new network settings, including your static IP configuration.

Step 6: Verify the new settings

Once you have applied the settings, verify the changes with the following command:

$ ip addr show

Check that the IP address displayed matches the static IP address you configured.

Troubleshooting

If you encounter any problems during the configuration process, consider the following:

Check the configuration file syntax

The Netplan configuration file must be properly formatted. Look for alignment issues, typos, and make sure the YAML syntax is observed correctly. Use yamlint or a similar tool to validate your file.

Review the network configuration

If the IP address does not display as expected, review the /etc/netplan/ configuration file for any errors. Check that the correct interface name is specified and make sure there are no conflicts with existing network devices.

DNS resolution issues

If you have DNS resolution issues after setting up a static IP, make sure your DNS server addresses are configured correctly in the configuration file.

Resetting the configuration

If necessary, you can revert to the original DHCP configuration by restoring the original contents of the netplan file and re-applying the settings with sudo netplan apply.

Conclusion

Configuring static IP on Ubuntu Server is a crucial step to ensure consistent network connectivity. By following the steps mentioned above, you can assign a static IP address and improve the reliability of your network services. Always remember to check your network details and validate your configuration files for errors before applying settings. With proper configuration, you can manage your server's connectivity more effectively, providing consistent access to users and services.

If you find anything wrong with the article content, you can


Comments