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 eth, enp, 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

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

3 days ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

4 days ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

5 days ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

1 month ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

1 month ago

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…

2 months ago