There are two ways of assigning IP addresses to a server or client machine. Most of the times we use DHCP to avoid additional work to assign IP addresses.
Dynamic Host Configuration Protocol (DHCP) is a way to assign IP addresses from a range of IP addresses and usually the action is performed by a router.
However, sometimes we need to assign static IP addresses when we want to login via SSH or perform particular actions from a remote host. In case of DHCP, the IP address may change if either of the device itself or the router is restarted. However, in case of static IP, the assigned IP always remained the same.
In this tutorial, we will see how to configure static IP addresses to Linux and Raspberry Pi operating systems.
For Ubuntu, we need to edit the
/etc/network/interfaces configuration file where we assign the static IP to a particular network interface.
iface enp0s3 inet static
dns-nameservers 22.214.171.124 126.96.36.199
In this example,
enp0s3 is the interface name. We add the static IP address, subnet mask, gateway, and DNS information in the file.
Red Hat Linux
Red Hat or
Cent OS are popular RPM-based server distributions. In case of setting static IP address, we will have to edit the interface file that resides in
/etc/sysconfig/networking-scripts/ directory. Therefore, the interface file path looks like-
_INTERFACE-NAME_ should be replaced with the interface name in your server.
Now, you will have to rewrite the configuration file as follows:
Here, you will have to set
static, and other information (IP address, subnet mask, gateway, and DNS information) as usual.
Raspbian OS, which is the mostly used OS in Raspberry Pi devices, you need to edit the
/etc/dhcpcd.conf file. Here, you have append the following types of information and then reboot your system.
$ nano /etc/dhcpcd.conf
# Append at the end of the file
That’s all for today! Cheers!!!