How to Set Static IP Address on Linux with the command line - The IP address is the logical address on a computer network, the IP address function is to connect each host that wants to connect on a network. Without an IP address, our device will not be recognized by other hosts.
In the distribution process, IP addresses are divided into 2 types, namely static IP and dynamic IP (DHCP). Static IP is an IP address that is configured manually and is fixed (unchanged), while dynamic IP or better known as DHCP IP is an IP address that is automatically obtained from the DHCP exchange process on the network.
In this tutorial, we will learn how to configure a static IP address on a computer that runs on a GNU / Linux based operating system. For a network engineer or system administrator, the ability to configure an IP address is a basic ability that must be mastered, therefore we must learn it.
Type the ifconfig command again, and the result is that the enp2s0 interface now has an IP address.
Don't forget to check routing entries with commands.
Finally, we test whether the computer can connect to sites on the internet or not. The trick is to run the ping command.
In this tutorial, we will learn how to configure a static IP address on a computer that runs on a GNU / Linux based operating system. For a network engineer or system administrator, the ability to configure an IP address is a basic ability that must be mastered, therefore we must learn it.
How to configure a static IP address on Linux
In this tutorial, I will simulate how to configure a static IP address on the Ethernet interface (enp2s0 or eth0). To get started please open your Linux terminal console, then run the ifconfig command to check what interfaces are on your computer.$ ifconfigFrom the above output, my ethernet interface turns out to be enp2s0. Next, I will add the IP address 192.168.1.2 and netmask 255.255.255.0 at the enp2s0 interface.
# ifconfig enp2s0 192.168.1.2 netmask 255.255.255.0So that the computer can recognize hosts that are outside the network, of course, we must add the default gateway.
# route add default gw 192.168.1.1Finally, we add the DNS entry to /etc/resolv.conf, the DNS function is as a resolver so that our computers can reach hosts on the internet based on the domain name.
# echo "nameserver 8.8.8.8" > /etc/resolv.confIf everything is done, we do a verification process to find out whether the above configuration has been successfully implemented or not.
Type the ifconfig command again, and the result is that the enp2s0 interface now has an IP address.
Don't forget to check routing entries with commands.
# route -nAnd it turns out the results of my computer already have routing entries to go to the internet network, see the picture below that I marked.
Finally, we test whether the computer can connect to sites on the internet or not. The trick is to run the ping command.
# ping www.geekswarrior.comIf the results have been replied, it means that our computer has successfully reached the site on the internet.