At some point, you might need to configure Ubuntu or any other Linux distribution with a static IP address. While you can’t change your external static IP address provided by your ISP, you can change your internal one, used within your home or office network.
How to Set a Static IP in Ubuntu Using the GUI
Setting a static IP in Ubuntu through the settings app is straightforward and doesn’t require technical knowledge. However, you’ll need the terminal to find the range of assignable IP addresses. Follow these steps:
- Find Available IP Range:
- Open a terminal session by pressing
Ctrl + Alt + T
. - Install net-tools with:
sudo apt install net-tools
- Note the range of IP addresses by using:
ifconfig -a
- Look under
inet
for the IP address and netmask (e.g.,192.168.1.176
and255.255.255.0
).
- Open a terminal session by pressing
- Set Static IP in Settings:
- Press the Windows Key (Superkey) and search for Settings.
- Select Wi-Fi if you’re connected via Wi-Fi or Network for Ethernet.
- Click the settings icon next to your connected network.
- Choose the IPv4 tab.
- Select Manual under IPv4 Method.
- Enter the IP address, Netmask, and Gateway you want to use, then click Apply.
Any changes will take effect immediately. To confirm your IP address, open the terminal with Ctrl + Alt + T
and type:
ip addr
How to Set a Static IP in Ubuntu Using the Terminal
For more technically inclined users, setting a static IP using the terminal is also possible. Here’s how:
- Display Network Information:
- Use the command:
nmcli connection show
- If
network-manager
isn’t installed, run:sudo apt-get install network-manager
- Use the command:
- Find Current IP and Default Gateway:
- Use the command:
ip addr
- Note the IP address (e.g.,
10.0.2.15
) and subnet mask (/24
indicates255.255.255.0
). - Find the default gateway with:
ip r
- Use the command:
- Add a Static Connection:
- Add a new static connection:
sudo nmcli con add con-name "static" ifname enp0s3 type ethernet ip4 10.0.2.13/24 gw4 10.0.2.2
- Add a new static connection:
- Set DNS, Enable Static IP:
- Set DNS servers:
nmcli con mod "static" ipv4.dns "1.1.1.1,8.8.8.8"
- Enable the connection:
nmcli con mod "static" ipv4.method manual nmcli con up "static" ifname enp0s3
- Set DNS servers:
- Verify New Connection:
- Check if the new connection is enabled with:
nmcli con show
- Check if the new connection is enabled with:
That’s it! You’ve successfully set up a static IP in Ubuntu.