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.
VirtualBox is a free, open-source, cross-platform virtualization application maintained by Oracle. It lets you run multiple…
PostgreSQL (also called Postgres) is a free, open-source, object-relational database management system with a strong reputation…
VMware Workstation Player is a mature, stable virtualization platform that lets you run multiple isolated operating…
A properly configured firewall is one of the most important layers of security for any internet-facing server. UFW (Uncomplicated Firewall) is a user-friendly front-end for managing iptables rules that ships pre-installed on Ubuntu. Its defaults are sensible: block all incoming connections, allow all outgoing connections. No outside traffic reaches your server unless you explicitly open a port. This guide covers how to configure a UFW firewall on Ubuntu 18.04, from setting default policies and application profiles to writing allow and deny rules for specific ports, IPs, and subnets. <strong>Prerequisite:</strong> You need sudo access. Configure UFW Firewall on Ubuntu: Defaults, SSH, and Application Profiles If UFW is not installed, add it with: bashsudo…
UFW (Uncomplicated Firewall) is a user-friendly front-end for managing iptables rules on Ubuntu. It ships pre-installed…
Apache Cassandra is a free, open-source NoSQL database designed for high availability and linear scalability with…