How to Setup Network Interface Card in CentOS

Now I will show how to setup a basic network configuration inside CentOS. The first thing you need to do is to boot up your CentOS and log into the root:

You may type ifconfig to display your current network configuration:



From the above picture, you can see that:
1)      eth0 – is your first network interface card inside your server
2)      lo – the loopback interface to access your local services such as proxy or webserver http://127.0.0.1

The network card settings can be found edit here:
vi /etc/sysconfig/network-scripts/ifcfg-eth0

SETUP STATIC IP

You may type like below inside your interface configuration file:
DEVICE=eth0
HWADDR=*
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.1.20
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
TYPE=Ethernet

*Note: Please leave your HWADDR as it is. Don’t delete or change from the original configuration

SETUP DHCP

In order to setup DHCP for the network interface card, just type like below inside the /etc/sysconfig/network-scripts/ifcfg-eth0 file:
DEVICE=eth0
HWADDR=*
ONBOOT=yes
BOOTPROTO=dhcp

*Note: Please leave your HWADDR as it is. Don’t delete or change from the original configuration

CONFIGURE DNS

Next is to configure the DNS in order for it to resolve your domain name request into IP for the server to understand it. To configure, type:
vi /etc/resolv.conf

Then you may add any DNS you want inside the file:
nameserver 202.75.34.1
nameserver 8.8.8.8

RESTART THE NETWORK SERVICE

After finished editing any of the network setting, you need to restart the network service in order for new changes to take effect. To restart, type:
/etc/init.d/network restart

You may type ifconfig to see your new network settings:

You also may test ping a domain name to see whether your network settings is working or not by typing:
ping google.com

If you got the reply, this means your setup was successful.

ASSIGN MULTIPLE IP IN NETWORK INTERFACE CARD

CentOS will have a slight difference from others in term of creating multiple IP usage. First, you need to copy the ifcfg-eth0 to the same location but with a slight name change:
cd /etc/sysconfig/network-scripts
cp ifcfg-eth0 ifcfg-eth0:1
vi ifcfg-eth0:1

Then you may edit the file like below:
DEVICE=eth0:1
HWADDR=*
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.1.40
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
TYPE=Ethernet



Don’t forget to change the DEVICE to according the file you rename.

*Note: Please leave your HWADDR as it is. Don’t delete or change from the original configuration

After saving and restarting the network, you can check your new setting by typing ifconfig


Leave a Reply