By default, computer IP addresses, including Windows, macOS, and Ubuntu/Linux, are dynamic. Dynamic IP addresses can be useful, especially for network administrators and experienced computer users, as they don't need to create individual IP addresses for each computer on the network.
However, suppose for some reason you want to set up a static IP address on Linux, Ubuntu, such as for gaming, improving internet connection speed, or port forwarding. Explore the Mytour article below to find out how to do it.
Configuring Static IP Address on Linux, Ubuntu
To set up a static IP address on Linux, Ubuntu, the first step is to install the Net Tools tool to display IP address information. To install this tool, open a Terminal window and enter the command below:
1. sudo apt install net-tools
The above command will install the Net Tools tool.
After successfully installing the tool, the next step is to check the IP address information by entering the following command in the Terminal window:
2. Ifconfig
Key information to remember includes the inet/ip address and netmask, highlighted in the box as shown below:
However, some information is missing, specifically DNS and gateway. To obtain this information, enter the following command:
3. nmcli dev show eno1
In the above command, replace 'eno1' with the network device name of your computer as displayed in the ifconfig command (such as eth0, ...). Key information to remember includes the numbers next to IP4.GATEWAY, IP4.DNS [1], and IP4.DNS [2].
Once you have all the information, the next step is to access the network connection editor on Linux, Ubuntu. The simple graphical interface allows users to easily customize IP settings. In the Terminal window, enter the following command:
4. nm-connection-editor
Next, select the device connected to the Internet, in this example, it's Wired connection 1, then click on tab IPv4 Settings. Change Method to Manual from the menu, then in the Address box, enter the following information:
- Address: Enter the static IP address you want to use. Note that this address must be within the same subnet and gateway range, so the last digits should match. In this example, the Gateway address is 192.168.0.1, so the static IP address is 192.168.0.11.
- Netmask: Enter the Netmask information displayed when running the 'ifconfig' command.
- Gateway: Refer to the information in 'nmcli dev show' and enter the Gateway address listed in the IP4.GATEWAY section.
- DNS servers: Similar to the Gateway address, enter the addresses listed in IP4.DNS [1] and IP4.DNS [2].
Once completed, click Save and access the Terminal. Enter the following command:
5. sudo service network-manager restart
Use the above command to restart your system and apply the static IP address configuration. To check if the static IP address is working, enter the command ifconfig in the Terminal window and verify if the new IP address is displayed. If not, simply restart your computer, and the new settings will take effect.
Mytour's article guides you through setting up a static IP address on Linux, Ubuntu. If you have any queries or questions, feel free to leave your comments below the article.
Explore changing IP addresses using commands on Linux rather than using graphical interfaces. The article on changing IP addresses using commands on Linux introduces essential IP change commands you should be familiar with.
Setting up a static IP is also a topic of interest for VNPT, FPT, and Viettel networks. Configuring a static IP is straightforward, requiring only a few simple steps.