RackNerd Billboard Banner

How to Set a Static IP Address in Ubuntu

If you’re running Ubuntu on a server or need consistent IP access for port forwarding, remote access, or networking, setting a static IP address is essential. DHCP (Dynamic Host Configuration Protocol) is fine for casual use, but static IPs are what you want for stability.

Here’s how to set a static IP address in Ubuntu, the right way.

Step 1: Know Your Network Details

Before you set a static IP, gather some key info:

  • Current IP address
  • Subnet mask
  • Gateway
  • DNS servers

You can get this by running:

ip a

And:

ip route

Also check DNS:

cat /etc/resolv.conf

Step 2: Edit Netplan Configuration (Ubuntu 18.04 and later)

Ubuntu now uses Netplan to manage networking. You’ll need to edit the relevant YAML file, typically found in /etc/netplan/.

sudo nano /etc/netplan/01-netcfg.yaml

The filename might vary (01-netplan.yaml, 50-cloud-init.yaml, etc.).

Step 3: Configure the Static IP

Here’s an example configuration for a static IP:

network:
  version: 2
  ethernets:
    enp3s0:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Replace:

  • enp3s0 with your network interface (found via ip a)
  • IP, gateway, and DNS with your network values

Step 4: Apply Changes

Save and apply the changes with:

sudo netplan apply

To test, run:

ip a
ping google.com

If you’re connected and the IP is static — you’re good to go.

Bonus Tip: Make Sure It’s Outside the DHCP Range

If your router hands out IPs from 192.168.1.2 to 192.168.1.100, don’t assign a static IP in that range or you’ll risk conflicts. Log into your router and check the DHCP settings before locking in your static IP.

Final Thoughts

That’s it — quick and clean. Setting a static IP in Ubuntu is just a matter of editing a YAML file, but getting the details right is key. Stick to the process and your Ubuntu machine will have a stable, predictable IP address every time it boots.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
RackNerd Billboard Banner
0
Would love your thoughts, please comment.x
()
x
Copy link