How To

Configure a Static IP Address on Ubuntu 18.04: Netplan Guide

Setting a static IP address on your server is a smart move. It ensures your machine keeps the same address every time it restarts. This makes it easy to host websites, run file servers, or connect over SSH without checking for a new address.

Ubuntu 18.04 uses a network management tool called Netplan. This tool replaced the older networking files used in earlier versions. Netplan uses files written in YAML format to configure your network ports.

This guide will show you how to configure a static IP address on Ubuntu 18.04 step by step.

Find Your Network Interface Name

You must identify the name of the network card you want to configure. Open your terminal and run this command:

baship link

Look at the output. You will see a loopback interface and one or more physical interfaces. The physical interface names usually start with letters like ethenp, or ens. Note down the exact name of the active interface you want to change.

Edit the Netplan Configuration File

Netplan stores its configuration files in the /etc/netplan/ directory. The file name usually ends with .yaml. Find the file name by listing the files in that directory.

Open the configuration file with a text editor like Nano:

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

If the directory is empty or you want to start fresh, you can create a new file. Paste the following settings into the file. Make sure to replace ens33 with your actual network port name:

yamlnetwork:  version: 2  renderer: networkd  ethernets:    ens33:      dhcp4: no      addresses:        - 192.168.1.100/24      gateway4: 192.168.1.1      nameservers:        addresses: [8.8.8.8, 1.1.1.1]

YAML files are very sensitive to spacing. Do not use tabs to indent the lines. Use two spaces for each level of indentation instead.

Here is what these settings mean:

  • dhcp4: no tells the system not to ask the router for an address automatically.
  • addresses is the static IP address you want to assign, followed by the subnet mask.
  • gateway4 is the IP address of your router.
  • nameservers sets the DNS servers the system uses to look up website names.

Save and close the file when you are done.

Apply the New Network Configuration

Test your changes to make sure there are no syntax errors in your YAML file. Run the netplan try command:

bashsudo netplan try

If the settings work, apply them permanently with this command:

bashsudo netplan apply

Check your new settings by running the IP address command:

baship addr show ens33

Confirm that the output shows the static IP address you set in the YAML file.

You have now set a permanent static IP address on your system. This setup will remain active even after your server restarts. If you ever need to go back to dynamic IP address settings, open the Netplan file again, set dhcp4 to yes, and remove the static address lines. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

1 week ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

1 week ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

1 week ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

2 weeks ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

2 weeks ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

2 weeks ago