How to Configure an IP Address on Ubuntu: Step-by-Step Guide

If you’re working with Ubuntu, knowing how to configure an IP address is essential—especially for servers, networking setups, and troubleshooting connectivity issues. This guide will walk you through different ways to set a static IP address or use DHCP on Ubuntu, whether you’re using the desktop GUI or the terminal.
Why Configure an IP Address on Ubuntu?
By default, most systems get their IP address from a DHCP server automatically. However, in many cases, you might want to manually configure a static IP address on Ubuntu:
- Hosting a web server or database server.
- Ensuring stable SSH connections.
- Setting up a local network for development or testing.
- Avoiding IP changes caused by DHCP leases.
Check Your Current IP Address in Ubuntu
Before changing anything, find out your current IP configuration.
Using the Terminal:
ip addr show
or:
ifconfig
(You may need to install net-tools
to use ifconfig: sudo apt install net-tools
)
Method 1: Configure IP Address on Ubuntu via GUI
If you’re on Ubuntu Desktop:
- Open Settings → go to Network.
- Select your wired or wireless connection.
- Click the gear icon next to your active network.
- Switch to the IPv4 tab.
- Choose Manual.
- Enter:
- Address: Your desired static IP (e.g., 192.168.1.100)
- Netmask: Usually 255.255.255.0
- Gateway: Your router’s IP (e.g., 192.168.1.1)
- Save changes and reconnect.
Method 2: Configure Static IP Address via Netplan (Ubuntu 18.04+)
Ubuntu uses Netplan for network configuration in newer versions.
- Open the Netplan config file:
sudo nano /etc/netplan/01-netcfg.yaml
- Add or modify the configuration:
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
- Apply changes:
sudo netplan apply
Method 3: Configure IP Address Temporarily with ip Command
If you just need a temporary IP address change until reboot:
sudo ip addr add 192.168.1.100/24 dev enp0s3
sudo ip route add default via 192.168.1.1
| ⚠️ This method won’t persist after restarting the system.
Troubleshooting IP Address Configuration
Restart networking service:
sudo systemctl restart NetworkManager
Flush old IPs:
sudo ip addr flush dev enp0s3
Check connectivity:
ping 8.8.8.8
Conclusion
Configuring an IP address on Ubuntu—whether static or via DHCP—is a fundamental skill for networking and server administration. For persistent changes, Netplan is the preferred method in modern Ubuntu versions. For quick adjustments, the ip command works well. With these steps, you can take full control of your Ubuntu network settings and avoid connection headaches.
FAQ
- How do I configure a static IP address in Ubuntu?
You can configure a static IP in Ubuntu using Netplan. Edit the YAML file in /etc/netplan/, add your IP, gateway, and DNS, then run sudo netplan apply.
- How do I check my IP address on Ubuntu?
Run the command ip addr show or ifconfig (after installing net-tools) to view your current IP address and network interface details.
- What is the difference between DHCP and static IP in Ubuntu?
- DHCP automatically assigns an IP from your router.
- Static IP is manually set and remains constant, useful for servers or permanent network devices.
- Can I set a temporary IP address in Ubuntu?
Yes, use the ip command:
sudo ip addr add 192.168.1.100/24 dev enp0s3
This change lasts until reboot.
- Why should I configure a static IP address on Ubuntu?
A static IP ensures reliable access for servers, SSH, file sharing, and port forwarding. It avoids changes caused by DHCP leases.