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.
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.
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.
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.
Xrdp is an open-source implementation of the Microsoft Remote Desktop Protocol (RDP). It lets you access…
Managing user accounts is one of the most basic system administration tasks on any Linux…
Wine (short for "Wine Is Not an Emulator") is a compatibility layer that lets you run…
KVM (Kernel-based Virtual Machine) is an open-source virtualization technology built into the Linux kernel. It lets…
Ubuntu 20.04 LTS (code name Focal Fossa) was released on April 23, 2020. It is a…
Google Chrome is the most widely used web browser in the world. It is fast, secure,…