Setting a static IP address in Ubuntu provides consistent network identification, which is essential for servers, network printers, or any device requiring reliable remote access. Unlike dynamic assignment via DHCP, a static configuration ensures the device retains the same address across reboots and network cycles.
Understanding Network Management in Modern Ubuntu
Contemporary Ubuntu releases utilize Netplan as the primary abstraction layer for network configuration. This system translates simple YAML definitions into the complex settings required by underlying backends like NetworkManager or systemd-networkd. Grasping this structure is the first step to managing addresses effectively.
Preparing to Configure the Static Address
Before editing files, you must identify the active network interface name. Utilities like ip a or ifconfig display interfaces such as enp0s3 or ens33. You also need the current gateway address and DNS servers, which can usually be found by checking the output of ip route or the router’s admin panel.
Backing Up Current Settings
Netplan files are located in the /etc/netplan/ directory, typically with a .yaml extension. It is critical to back up the original file before making changes. This safety measure allows you to revert instantly if the new syntax contains an error or the configuration does not behave as expected.
Configuring Netplan with Static Details
Edit the existing YAML configuration using a text editor like nano or vim. You must replace the DHCP settings with a structured static definition. Below is a standard template demonstrating the correct indentation and required parameters.
Applying the Configuration
After saving the YAML file, validate the syntax to avoid breaking the network session. Execute sudo netplan try to test the changes; if connectivity drops, the command will automatically revert to the previous working setup after a timeout. Once confirmed, apply the settings permanently with sudo netplan apply .
Verifying the Static Configuration
Reboot the system or restart the networking service to ensure persistence. Use ip addr show to verify that the interface holds the correct address. Additionally, pinging the gateway and an external domain name confirms that both layer-3 connectivity and DNS resolution are functioning correctly.
Troubleshooting Common Issues
If the interface fails to come up, check for typos in the YAML file, particularly indentation, as spaces are strictly significant. Ensure the static address does not overlap with the DHCP pool managed by your router to prevent IP conflicts. Consult system logs with journalctl -xe to identify backend errors if the connection remains unstable.