There comes a time when you might have to configure Ubuntu or any other Linux distribution with a static IP address. While you can't change your external static IP address, since it's the one your internet service provider provides, you can change your internal one. This is the IP address used on your network inside your home or office.
Though many tasks on Ubuntu usually require you to visit the terminal app and deal with lines of text, changing your internal IP is easy. You can do this through the settings app and the Graphical User Interface (GUI). Of course, if you want, you can also swap things out by going through the terminal. Here's how.
How to set static internal IP in Ubuntu using the GUI
Without any technical know-how or knowledge, you can set a static IP in Ubuntu through the settings app. Just note, you will have to use the terminal once to find a range of IP addresses that you can assign. Once you do that, you just tap the Windows Key or the Superkey on your device and search for Settings. Once the app is open, proceed with the steps below.
- If you're connected to the internet via Wi-Fi, choose Wi-Fi. If you're connected via Ethernet, select Network.
- Once the interface is open, click the settings icon next to the network you're connected to.
- From the list of tabs at the top, choose IPv4.
- Under ipv4 method, be sure to choose Manual.
- Under Addresses, enter the IP address, the Netmask, and the Gateway you want to use. For finding IP addresses that'll work on your network, you can proceed with the steps below.
- Open a terminal session. With Ctrl, Alt, and T. Install net-tools with the command sudo apt install net-tools.
-
Note down the range of IP addresses you'll be able to use. Use the command ifconfig -a. The result will be listed under inet.
- In this case, we have an inet of 192.168.1.176 and a netmask of 255.255.255.0. We can enter those numbers and can calculate the usable range using this website.
- When you've calculated the usable range of addresses, choose a valid IP address that falls within this range. Then, you can click Apply at the top.
Any changes you apply will automatically go into effect. If you want, you can also use the terminal to confirm your IP address. Launch it with Ctrl, Alt, and T on your keyboard. Once launched, enter the command ip addr or ip a. You should see an interface IP address listed.
How to set static internal IP in Ubuntu using the Terminal and Text Editor
If you're a bit more technical and want to set a static IP in Ubuntu using the terminal, that is possible. You'll have to edit some lines of text and go through a few extra steps, but here's how:
-
Display information about your network. Use the command nmcli connection show. You'll see a network name, a UUID, a Type, and a Device. If this package isn't installed (though it should be, as it comes preinstalled with Ubuntu), then run
sudo apt-get install network-manager
- Note down the range of IP addresses you'll be able to use. Use the command ip addr to find out your machine's current IP address. This tutorial assumes that your network adapter is called enp0s3. If it isn't, then look for the correct one and also change the interface names in the subsequent commands. In the above example, we have an inet of 10.0.2.15, with the /24 denoting that the network uses a 255.255.255.0 subnet mask. In most cases, your usable network range will be whatever is in the first three places of the internal IP address, and then any unused number on your network between 1 and 255 in the last section. For example, we can use 10.0.2.16. If you're unsure, you can enter the subnet mask and your internal IP address into this website to calculate the usable range.
- Note the IP address of your default gateway with the command ip r. In our example, it's 10.2.2.2.
-
Next, we'll add a new static connection option. Run the following command, making sure to change the numbers after "ip4" and "gw4" depending on your network conditions. These are the IP address you want to change your machine to and the current default gateway, respectively.
sudo nmcli con add con-name "static" ifname enp0s3 type ethernet ip4 10.0.2.13/24 gw4 10.0.2.2
In our case, we do the following. -
Set your DNS, manual DHCP (so, a static IP), and enable the connection. You can do that by running the following commands in succession.
nmcli con mod "static" ipv4.dns "1.1.1.1,8.8.8.8"
You can swap out the DNS servers above for whatever you want, they are in order of primary and secondary.nmcli con mod "static" ipv4.method manual; nmcli con up "static" ifname enp0s3
Once done, you can run nmcli con show to see if the new connection is enabled. If the output above looks like yours, then you're ready to go!
Setting complete
That's all you need to set up a static IP in Ubuntu. It doesn't take much effort. Remember, we're always writing about Linux, so you can check out our guide to the best Linux laptops should you need one.
