In this tutorial, I will be using Ubuntu 16.04 operating system. This tutorial assumes that you know how to edit a file in Linux.
First, execute the below command to open interfaces file:
sudo vi /etc/network/interfaces
After that, depending on your system network card configuration, you may see the below format in vi editor.
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp
In the last line you will see
iface eth0 inet dhcp. If you have multiple network cards, you will see multiple lines eth0, eth1, etc. But for the purpose of this tutorial, I will set
eth0 to static IP address.
iface eth0 inet dhcp to
iface eth0 inet static. Now to go to the next line by pressing enter. Add 4 spaces and add below address to gateway syntex as shown in below example:
iface eth0 inet static address 192.168.0.150 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.254 dns-nameservers 192.168.0.254
Note: Network settings may vary depending on your network configuration. If you are not sure, please reach out to your network administrator. If you are doing this in your home lab environment. Feel free to leave a comment below and I would be happy to assist you.
Now save the interfaces file and follow the below steps to restart eth0 interface.
sudo ifdown eth0; sudo ifup eth0
Once the restart is completed, check whether the IP address is assigned or not by executing the below command:
If you are seeing the correct IP address, that means you have successfully assigned the IP address.