How to Configure a Static IP Address in Linux: Netplan, nmcli & Debian Guide

Premium services since 2010

Trusted by thousands of businesses worldwide • 99.9% Uptime Guarantee • Crypto Accepted

Table of Contents

How to Configure Static IP Address on Linux VPS

When deploying production services, DNS nameservers, web hosting panels, or database clusters on a Linux VPS or dedicated server, configuring a permanent static IP address prevents IP lease churn, DHCP renewal drops, and network unreachable errors. Modern Linux distributions have transitioned away from legacy network scripts (like /etc/sysconfig/network-scripts/ifcfg-eth0) to declarative network renderers like Netplan (Ubuntu/Debian) and NetworkManager / nmcli (AlmaLinux, Rocky Linux, RHEL).

This technical guide provides step-by-step instructions for configuring static IPv4 and IPv6 network adapters on Ubuntu 24.04 / 22.04 LTS, Debian 12, and AlmaLinux / Rocky Linux 9 & 8, configures primary DNS nameservers, and verifies routing reachability. If you are hardening management access on your server, see our guides on How to Change Default SSH Port and CSF Firewall Setup.

Prerequisites: Identifying your network interface name

Before modifying configuration files, determine your active Ethernet interface identifier (commonly eth0, ens3, ens18, or enp1s0):

# List network interfaces and current IP assignments
ip -br a

Note your target interface name (e.g. eth0), assigned static IP (e.g. 198.51.100.50/24), default gateway (e.g. 198.51.100.1), and upstream DNS resolvers (8.8.8.8 and 1.1.1.1).

Method 1: Configure static IP on Ubuntu 24.04 / 22.04 (Netplan)

Ubuntu uses Netplan YAML configuration files located under /etc/netplan/ (e.g. /etc/netplan/50-cloud-init.yaml or /etc/netplan/01-netcfg.yaml):

  1. Open your Netplan configuration file in a text editor:
    sudo nano /etc/netplan/50-cloud-init.yaml
  2. Update the YAML structure with strict 2-space indentation (avoid tab characters):
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: false
          addresses:
            - 198.51.100.50/24
          routes:
            - to: default
              via: 198.51.100.1
          nameservers:
            addresses: [8.8.8.8, 1.1.1.1]
  3. Test and apply the network configuration:
    # Validate syntax and apply changes
    sudo netplan apply

Method 2: Configure static IP on AlmaLinux / Rocky / RHEL (nmcli)

Modern Enterprise Linux distributions use NetworkManager. Configure your interface safely in two commands using nmcli:

  1. Modify the connection profile with your static IP, subnet, gateway, and manual assignment mode:
    # Assign static IP, gateway, and disable DHCP
    sudo nmcli con mod eth0 ipv4.addresses 198.51.100.50/24 ipv4.gateway 198.51.100.1 ipv4.method manual
  2. Set persistent DNS nameservers and bring up the connection:
    # Set DNS resolvers and reactivate network connection
    sudo nmcli con mod eth0 ipv4.dns "8.8.8.8 1.1.1.1" && sudo nmcli con up eth0
Static IP Configuration on Ubuntu Netplan and AlmaLinux NetworkManager

Method 3: Configure static IP on Debian 12 (/etc/network/interfaces)

On standalone Debian 12 servers utilizing traditional ifupdown networking:

  1. Edit /etc/network/interfaces:
    sudo nano /etc/network/interfaces
  2. Define the static interface block:
    auto eth0
    iface eth0 inet static
        address 198.51.100.50
        netmask 255.255.255.0
        gateway 198.51.100.1
        dns-nameservers 8.8.8.8 1.1.1.1
  3. Restart the networking service:
    sudo systemctl restart networking

Step 4: Verify IP assignment and internet gateway routing

Validate your network state and DNS resolution using these diagnostic commands:

  • Check Active IP Address: ip addr show dev eth0
  • Test Default Gateway Ping: ping -c 3 198.51.100.1
  • Verify DNS Name Resolution: ping -c 3 google.com

For remote desktop environments on Linux, see our setup guides on Ubuntu Desktop with XRDP and VNC with XFCE Desktop.

For high-reliability infrastructure with dedicated static IPv4/IPv6 subnets and 1Gbps unmetered bandwidth, explore Aminserve Linux Cloud VPS and Swiss Dedicated Servers.

Never Miss an Update

Get expert tips, tutorials, and hosting insights delivered to your inbox weekly. Join 10,000+ subscribers!
🔒 We respect your privacy. Unsubscribe anytime.