TSF – Giải pháp IT toàn diện cho doanh nghiệp SMB | HCM

How to set ip address static on ubuntu server 22.04

Setting up a static IP address on Ubuntu Server 22.04 is a fundamental task when building a reliable and stable server environment. Unlike DHCP-assigned IP addresses that may change after reboot, a static IP ensures your server always uses the same address—critical for management, monitoring, and hosted services.

In this guide, you will learn how to configure a static IP address using Netplan, the default network configuration tool in Ubuntu 22.04. The tutorial covers identifying the active network interface, disabling cloud-init network configuration, editing the Netplan YAML file, applying changes safely, and verifying connectivity.

This configuration is especially important for servers running services such as GLPI, Zabbix, Apache, Nginx, or database servers.


🎯 Why Use a Static IP on Ubuntu Server?

✅ Ensures consistent server IP after reboot
✅ Required for hosting services and production workloads
✅ Improves reliability for monitoring and remote access
✅ Prevents IP conflicts in managed networks

📌 A static IP is considered a best practice for all production servers.


🧰 Prerequisites

Before starting, make sure you have:

🔹 Ubuntu Server 22.04 installed
🔹 SSH access to the server
🔹 A user account with sudo privileges
🔹 Network information (IP, gateway, DNS)


⚠️ Important Notes Before Configuration

⚠️ Incorrect network settings may cause loss of SSH connectivity
⚠️ Always double-check the interface name and IP details
⚠️ Apply changes carefully, especially on remote servers

📌 It is recommended to perform this configuration during a maintenance window.


🛠️ Step-by-Step: Configure Static IP on Ubuntu Server 22.04

🔹 Step 1: Check Current IP Address (SSH)

➡️ Verify the current IP address used to access the server via SSH.


🔹 Step 2: Disable cloud-init Network Configuration

➡️ Create a new configuration file:

 
sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

Add the following content:

 
network: {config: disabled}

Save the file:

  • Press Ctrl + O, then Enter

  • Exit with Ctrl + X


🔹 Step 3: Remove Old cloud-init Network Configuration File

➡️ Remove the existing network configuration file created by the installer:

 
sudo rm /etc/cloud/cloud.cfg.d/90-installer-network.cfg

📌 This prevents cloud-init from overwriting your Netplan configuration.


🔹 Step 4: Edit Netplan YAML Configuration File

➡️ Open the Netplan configuration file and configure the static IP:

💻
filename.bash
network:
  version: 2
  ethernets:
    ens18:
      dhcp4: no
      addresses:
        - 192.168.16.160/24
      gateway4: 192.168.16.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 1.1.1.1
          

📌 Make sure the interface name (ens18) matches your system.

Save the file, then apply the configuration:

 
sudo netplan apply
sudo reboot

🔹 Step 5 (Optional): Set System Timezone (Vietnam)

➡️ If your server is located in Vietnam, set the correct timezone:

 
sudo timedatectl set-timezone Asia/Ho_Chi_Minh

🔎 Verification After Configuration

After reboot, verify the configuration:

✔️ Confirm the server uses the new static IP
✔️ Test SSH connectivity
✔️ Verify internet access (ping gateway / DNS)
✔️ Check DNS resolution

📌 The server should now maintain the same IP address across reboots.


🧠 Common Issues & Troubleshooting

🔧 Lost SSH connection:

  • Verify Netplan YAML indentation

  • Confirm correct interface name

  • Check gateway and subnet

🔧 No internet access:

  • Verify DNS configuration

  • Test connectivity to gateway



🧠 Conclusion

Configuring a static IP address on Ubuntu Server 22.04 is a critical step in preparing your server for production use. With a properly configured static IP, your system becomes more reliable, predictable, and easier to manage.

By following this guide carefully and keeping the technical flow intact, you can safely deploy Ubuntu Server in real-world environments with confidence.

See also related articles

How to set ip address static on ubuntu server 22.04

How to set ip address static on ubuntu server 22.04 Setting up a static IP address on Ubuntu Server 22.04 is a fundamental task when building a reliable and stable server environment. Unlike DHCP-assigned IP addresses that may change after reboot, a static IP ensures your server always uses the...

Read More