In Linux operating system, we can configure IP address in two ways. One is using graphical mode and the other is using command line mode. Again, during the operating system installation time an IP address can be configured. However, in order to configure the IP address graphically, the graphical environment must be pre-installed. In this tutorial, we will learn how to configure IP using command line mode.
We know that, when a network interface card is inserted into the Linux operating system, a script file is generated. By editing that script file, we can configure the IP address for that network interface card. The location of the file is: -
One thing we need to keep in mind here is that, the name for the first network card will be “ifcfg-eth0”, then the name for the second will be “ifcfg-eth1”, the name for the third will be “ifcfg-eth2”, and so on.
Now we will open the script of that network card using “VI editor”. If you want, you can use any editor other than "VI Editor". The complete command to open the file is: -
Since, after opening the file it will be in “read only” mode, so we will have to go to “insert” mode. To go into “insert” mode we need to press “i” from the keyboard.
After opening the file, we will add some lines here. The lines are: -
IPADDR=192.168.3.150
NETMASK=255.255.255.0
GATEWAY=192.168.3.253
One thing to note here is that, by default Linux operating system enables "dhcp" mode for IP address configuration.
So we have to add the above lines as well as disable the "dhcp" mode. To disable "dhcp" we need to set “BOOTPROTO = static” or "none”.
So the changes we need to make to the file are: -
BOOTPROTO=static
IPADDR=192.168.3.61
NETMASK=255.255.255.0
GATEWAY=192.168.3.253
Here is a screenshot:
After changing the value, we will exit the "insert" mode by pressing the "escape" button. At the end of all, we will save and close the file using the following command.
After configuring our IP address, we have to configure our DNS address. The file we need to edit to configure the DNS address is: -
After opening the file, we will add the following line.
nameserver 10.10.10.5 (ip address of our dns server)
If we want, we can add more lines and configure many dns servers. E.g.
nameserver 10.10.10.5 (ip address of our dns server)
nameserver 172.16.5.239 (ip address of our dns server)
Here is a screenshot:
If we have already added a "nameserver", we can edit the existing lines if we want without creating new lines. After saving the file, we need to restart the network service once. That is why the command is:-
This time we can check our IP address using the following command.
No comments:
Post a Comment