How to Configure a Static IP on a Linux VPS

Most VPS providers assign a static (unchanging) IP address by default, but understanding how network configuration works is important when troubleshooting connectivity or setting up advanced networking. This guide covers verifying and configuring static IP settings.

Step 1 — Check Your Current IP Configuration

ip addr show

Step 2 — Identify Your Network Interface

ip link show

Common interface names include eth0, ens3enp0s3 depending on your virtualization platform.

Step 3 — Locate the Network Configuration File

Modern Ubuntu/Debian systems use netplan:

ls /etc/netplan/

Step 4 — Configure a Static IP with Netplan

sudo nano /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 203.0.113.10/24
      gateway4: 203.0.113.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]

Replace values with those provided by your VPS host — using incorrect values here can disconnect you from the server entirely.

Step 5 — Test the Configuration Before Applying Permanently

sudo netplan try

netplan try applies the change temporarily and automatically reverts if you don't confirm within a countdown — a safety net against locking yourself out with a bad configuration.

Step 6 — Apply the Configuration

sudo netplan apply

Step 7 — Verify Connectivity

ping -c 4 8.8.8.8
ip addr show

Important: Most VPS Providers Manage This For You

On most standard VPS setups, your provider's infrastructure (cloud-init, DHCP with a static lease) already assigns a static IP automatically — manual configuration is typically only needed for advanced scenarios like adding a secondary IP, private networking, or migrating between providers with different network requirements.

Adding a Secondary IP Address

network:
  ethernets:
    eth0:
      addresses:
        - 203.0.113.10/24
        - 203.0.113.11/24

Common Errors

Lost connectivity after applying a network config change — use your provider's web console to fix the configuration, since SSH itself relies on the network being correctly configured. This is exactly why netplan try exists as a safety measure.

"Cannot find device" error — the interface name in your config doesn't match the actual device name; verify with ip link show.

Best Practices

  • Always use netplan try (or an equivalent safety mechanism) before permanently applying network changes
  • Keep your provider's console access available before making any network configuration change
  • Document your network settings in case you need to reference them during a migration

Related Articles

  • How to Configure Multiple IP Addresses on One VPS
  • How to Enable and Configure IPv6 on Your VPS
  • VPS Unreachable/Can't Connect via SSH: Troubleshooting Guide
  • static ip, netplan, network configuration, linux networking
  • 0 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?

Seotud artiklid

DNS Fundamentals: A, AAAA, CNAME, MX, TXT & NS Records Explained

DNS translates human-readable domain names into the information servers actually need — IP...

How to Point a Domain to Your VPS (A/AAAA Records)

Before your website is reachable at yourdomain.com instead of a raw IP address, you need to...

How to Configure MX Records for Email Delivery

MX (Mail Exchange) records tell the internet which servers handle incoming email for your domain....

How to Use CNAME Records Correctly

CNAME records let you alias one domain name to another, but they come with important restrictions...

How to Enable and Configure IPv6 on Your VPS

IPv6 adoption continues to grow, and many VPS plans include a free IPv6 address alongside IPv4....