How to Manually Configure a Static IP Address in Ubuntu
By default, Ubuntu uses Netplan to manage network configurations. Follow these steps to manually configure a static IP address.
Step 1: Check Available Network Interfaces
Before modifying the configuration, determine your network interface name.
Open the terminal and run:
ifconfig -aIf ifconfig is not installed, use:
ip aLook for an interface name similar to ens33, ens34, eth0, or wlp2s0 (for wireless).
Step 2: Navigate to the Netplan Directory
Netplan configuration files are stored in /etc/netplan/. Navigate to the directory:
cd /etc/netplan
- Edit the .yaml file inside the directory to set a static IP:
network:
version: 2
ethernets:
ens34:# Your network adapter id name
dhcp4: no # disable DHCP service
addresses: [192.168.1.109/24] # Static IP address
gateway4: 192.168.1.7 # Default Gateway
nameservers:
addresses: [192.168.1.7,8.8.8.8]
Step 3: Apply the Configuration
To test the configuration before applying, run:
sudo netplan tryIf everything is correct, you will see a message saying the changes are applied temporarily for 120 seconds. If something goes wrong, the system will revert.
To permanently apply changes, run:
sudo netplan applyStep 4: Verify the Configuration
Check if the static IP is set correctly:
ip aor
ifconfigYou can also test network connectivity:
ping 8.8.8.8 -c 4Conclusion
You've successfully configured a static IP address on Ubuntu using Netplan. If you encounter issues, check your YAML file for indentation errors or revert to DHCP by setting dhcp4: yes
If you found this guide helpful, consider supporting me!