Here is how to configure static IP on Ubuntu. By default, your server gets its IP address from DHCP. That works, until a reboot or a network change hands it a different address, and anything that depended on the old IP (firewall rules, DNS records, SSH scripts) breaks. A static IP fixes that once and for all.
Why a static IP matters
Ubuntu servers often start life as a quick VM or a fresh install, spun up fast with DHCP handling the network so you can get to work right away. That is fine for testing. It becomes a problem the moment that server starts running something other people or systems depend on: a web app, an API, a mail relay. A reboot that hands out a new IP breaks every connection, firewall rule, and DNS record pointed at the old one.
A static IP is the fix. Set it once, and Ubuntu keeps that address through every reboot from then on, no surprises.
What you need
- A Hostner dedicated server running Ubuntu
- Root or sudo access via SSH
- Your server’s IP address, netmask, and gateway (find these in your Hostner dashboard)
Step 1: Find your network interface
Log in via SSH, then run:
~ $ ip a
Look for the interface that is not lo (that one is just the local loopback). It is usually named something like ens18 or eth0. Note the name, you need it in the next step.
Step 2: Configure static IP on Ubuntu
Ubuntu uses Netplan for network configuration. Open the config file:
~ $ sudo nano /etc/netplan/01-netcfg.yaml
Replace its contents with:
~ $ network: ~ $ version: 2 ~ $ ethernets: ~ $ ens18: ~ $ dhcp4: no ~ $ addresses: [YOUR_IP/24] ~ $ gateway4: YOUR_GATEWAY ~ $ nameservers: ~ $ addresses: [8.8.8.8, 1.1.1.1]
Replace ens18 with your actual interface name, and YOUR_IP / YOUR_GATEWAY with the values from your Hostner dashboard. Netplan is picky about indentation, so use spaces, not tabs. The official Netplan documentation covers more advanced configurations if you need more than a single static address. Save the file and exit.
Step 3: Apply the configuration
Run:
~ $ sudo netplan apply
If this command hangs or the connection drops and does not come back, do not panic. Reconnect through your Hostner KVM/IPMI console instead of SSH, and double-check the values you entered, especially the indentation.
Step 4: Confirm it worked
Run ip a again. Your interface should now show the static IP you set, not the old DHCP one. Test the connection with:
~ $ ping google.com
If it does not work
A typo in the gateway or a broken indentation in the Netplan file is the most common cause of a dropped connection. If SSH stops responding after applying the config, use the console access in your Hostner dashboard to fix the file directly, since a wrong static IP can lock you out over the network entirely.
If the connection comes back but routing seems off (you can ping local addresses but not the internet), check that the gateway you entered actually matches your network. Run ip route to see the current routing table and compare it against the gateway from your Hostner dashboard.
No ticket needed. Once you configure static IP on Ubuntu correctly, it stays that way through every reboot, every power cycle, and every network hiccup, so you can stop worrying about it and move on to the next thing.
Also available for: Debian, AlmaLinux. See all guides in Docs.