Configure network interface part 2

0

On this article we will know only about how to configure network interface using text mode. So as we know there we have to work on four files those are given below:

  1. /etc/sysconfig/network-scripts/ifcfg-(Device Name)
  2. /etc/ sysconfig/network
  3. /etc/hosts
  4. /etc/resolve.conf

First of all we need to configure the device file, which is /etc/sysconfig/network-scripts/ifcfg-(Device Name). For my system the device name is enp0s3. So our configuration file will be /etc/sysconfig/network-scripts/ifcfg-enp0s3.

#vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

Now we will get the file to edit. Initially we will see the file as shown below.

HWADDR=00:0C:29:58:2C:95

TYPE=Ethernet

NAME=enp0s3

BOOTPROTO=dhcp

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

USERCTL=no

NM_CONTROLLED=yes

IPV4_FAILURE_FATAL=no

ONBOOT=no

After we get this we have to add few lines and we have to edit few lines on the device file. So what are the lines we need to edit first! Those lines are given below.

BOOTPROTO=dhcp

NM_CONTROLLED=yes

ONBOOT=no

Now we have to edit these lines according to below.

BOOTPROTO=static

NM_CONTROLLED=no

ONBOOT=yes

Once these lines are edited then we have to add few lines with it. Those are given below.

IPADDR=192.168.1.64

PREFIX=24

GATEWAY=192.168.1.1

DNS1=192.168.1.1

DNS2=8.8.8.8

Now change the ip address, prefix number, gateway and dns as provided by the ISP. Then simply save and exit the file. After that run a command to recheck the file.

#cat /etc/sysconfig/network-scripts/ifcfg-enp0s3

The output will be like

HWADDR=00:0C:29:58:2C:95

TYPE=Ethernet

NAME=enp0s3

BOOTPROTO=dhcp

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

USERCTL=no

NM_CONTROLLED=yes

IPV4_FAILURE_FATAL=no

ONBOOT=no

IPADDR=192.168.1.64

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

DNS1=192.168.1.1

DNS2=8.8.8.8

 

Once this work is done we have successfully completed 50% our work. The network will work if we edit this file only. Now to make it more accurate we need to edit the rest of three files.

One this step we have to edit the file /etc/sysconfig/network. This file is important when we have more than one gateway to work with.

We need to add three lines on this file.

NETWORKING=yes

HOSTNAME= testserver

GATEWAY=192.168.1.1

Now we will edit the third file which is /etc/hosts. This file helps to resolve the server itself and the servers we need to know from the network. So we have to add the below line at the end of the file.

192.168.1.64   testserver.doamin-name.com            testserver

Then we have to save and exit from the file. Now we have only one file left to edit and we are done with our network configuration.

The last file is /etc/resolve.conf.

Here we have to add the name servers using either IP address or by using domain names.

Top open this file we have to use the vi or vim editor again.  So that will be like as mentioned in below.

#vi /etc/resolve.conf

We have to add the nameservers at the end of the file and then we have to save the file and exit the file.

nameserver 192.168.1.1

nameserver 8.8.8.8

Once we are done with all those above work we are ready to restart the network service. For that we have to run the command mentioned below.

#systemctl       restart network

Or

#/etc/init.d/network   restart

On this stage we can say that our network ready to use. So to be sure we will run another command and make sure that our network is working properly.

#ping 192.168.1.1

If we get response from the ping then we can start our rest of the work without wasting time.

Leave A Reply

Your email address will not be published.