How to Configure a DHCP or Static IP on Ubuntu Server

Published March 7, 2025
How to Configure a DHCP or Static IP on Ubuntu Server
Cheap Dedicated Server

How to Configure a DHCP or Static IP on Ubuntu Server


How to Configure a DHCP or Static IP on Ubuntu Server

Configuring network settings on Ubuntu Server is a crucial step in setting up a reliable and stable system. Whether you need a dynamically assigned IP address via DHCP or a fixed static IP, Ubuntu provides simple ways to configure your network settings.

Configuring a DHCP IP Address

By default, Ubuntu Server typically obtains an IP address via DHCP. If you need to ensure your server continues to use DHCP, follow these steps:

  1. Open the Netplan configuration file:
    Open the Netplan configuration file
    sudo nano /etc/netplan/00-installer-config.yaml
    
  2. Ensure the following configuration is set:
    Ensure the following configuration is set
    network:
      ethernets:
        eth0:
          dhcp4: true
      version: 2
    

    Replace eth0 with your actual network interface name if different.

  3. Apply the changes:
    sudo netplan apply
    

Configuring a Static IP Address

If your server requires a fixed IP address, configure it manually:

  1. Open the Netplan configuration file:
    sudo nano /etc/netplan/00-installer-config.yaml
    
  2. Modify it to include your static IP configuration:
    Modify it to include your static IP configuration
    network:
      ethernets:
        eth0:
          dhcp4: false
          addresses:
            - 192.168.1.100/24
          gateway4: 192.168.1.1
          nameservers:
            addresses:
              - 8.8.8.8
              - 8.8.4.4
      version: 2
    

    Adjust the IP address, gateway, and DNS servers as needed.

  3. Save the file and apply the changes:
    sudo netplan apply
    

Verifying Network Configuration

To check if your changes were applied correctly, use:

ip a

Or to check your default gateway:

ip route

Conclusion

Setting up a DHCP or static IP on Ubuntu Server is straightforward with Netplan. Whether you prefer automatic configuration via DHCP or require a fixed address, these steps ensure a stable network connection.


 

 

How to Configure a DHCP or Static IP on Ubuntu Server (F.A.Q)

 

How do I find my network interface name?

Use the command ip link show or ls /sys/class/net/ to list available interfaces.

 

What happens if my network goes down after applying changes?

Ensure the syntax in your Netplan file is correct. If needed, revert changes using sudo nano /etc/netplan/00-installer-config.yaml and correct the file.

Can I use both DHCP and a static IP on different interfaces?

Yes, you can configure multiple interfaces separately in the Netplan file, specifying DHCP for one and a static IP for another.

 

How do I restart networking without rebooting?

Run sudo netplan apply or restart the networking service using sudo systemctl restart systemd-networkd.