How to Configure a Static IP on Ubuntu 18.04 Server?

Learn how to configure a static IP on Ubuntu 18.04 server using NetPlan. Follow this step-by-step guide to set up a stable IP address for your server.

Static IP on Ubuntu

Setting up a static IP address on Ubuntu 18.04 is different compared to earlier versions like Ubuntu 14 or Ubuntu 16. In Ubuntu 18.04, the network configuration is managed using a tool called NetPlan, replacing the old /etc/network/interfaces file used in previous versions.

NetPlan uses YAML configuration files stored in the /etc/netplan/ directory to manage network interfaces. There are two types of renderers for NetPlan:

  1. NetworkManager - Commonly used on desktop systems.

  2. networkd - Commonly used on servers.

Steps to Configure a Static IP Address Using networkd

Step 1: Identify the Active Network Interface

First, identify the network interface you want to configure. Use the following commands to list all network interfaces:

bash
 
ifconfig -a 
                                    

or

bash
 
ip a 
                                    

Step 2: Create or Edit a NetPlan Configuration File

If a YAML configuration file doesn’t already exist in the /etc/netplan/ directory, you can generate one using this command:

bash
 
netplan generate 
                                    

Step 3: Set a Static IP Address

Open the NetPlan configuration file using a text editor like vim or nano. For example:

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

Add or edit the configuration under the relevant network interface (e.g., eth0) to look like this:

yaml
 
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.1.8/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4 
                                    

Step 4: Apply the Configuration

Save and close the file, then apply the changes using the NetPlan command:

bash
 
sudo netplan apply 
                                    

Step 5: Verify the Configuration

Check if the new IP address is active:

bash
 
ifconfig -a 
                                    

Test connectivity to ensure the configuration works:

bash
 
ping 8.8.8.8 
                                    

Conclusion

You have now successfully configured a static IP address on your Ubuntu 18.04 server using NetPlan. If you have any questions or face issues, feel free to contact us, and our team will assist you.

Discover iDatam Dedicated Server Locations

iDatam servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.

Up