Configure Network in CentOS 7 / CentOS 6

CentOS 7 Logo
Configure Network in CentOS 7

Just after the installation of CentOS 7, you must configure network in order to access your system from outside. This guide helps you to configure network in CentOS 7 / CentOS 6.

Here i will show you assigning ipaddress in Static and in DHCP mode .

Note: Below tutorial was tested on CentOS 7 Minimal installation.

Static Mode:

In this mode, we will manually assign ipadress to machines. Lets check the available interfaces on our system.

[root@server ~]# ip a

1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:76:96:a8 brd ff:ff:ff:ff:ff:ff

From the above output, you can see my system has two interfaces namely “lo” and “eno16777736“. Depends on hardware, name of the interface will change.

Now, we will set ipaddress to an interface “eno16777736“. To do that, go to /etc/sysconfig/network-scripts/ directory, there you will find a file “ifcfg-<interfacename>“. As per above output, my system has a file “ifcfg-eno16777736“.

Edit the “ifcfg-eno16777736” file.

# cd /etc/sysconfig/network-scripts/

# vi ifcfg-eno16777736

HWADDR=00:0C:29:76:96:A8
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=e5a5d8e9-b5d4-4b5e-bd1e-6ebcd0144dfa
ONBOOT=no

Just modify the lines like this.

HWADDR=00:0C:29:76:96:A8
TYPE=Ethernet
BOOTPROTO=none  ## Enabled Static Mode
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=e5a5d8e9-b5d4-4b5e-bd1e-6ebcd0144dfa
ONBOOT=yes  ## Interface enabled
IPADDR=192.168.12.10  ## IP Address
NETMASK=255.255.255.0  ## Subnet Mask
GATEWAY=192.168.12.2  ## Default Gateway
DNS1=8.8.8.8  ## DNS Server 1
DNS2=8.8.4.4  ## DNS Server 2
DOMAIN=itzgeek.local  ## Local Search Domain

Restart the network service using below command.

# service network restart

Now you can see the ip address “192.168.12.10” assigned to the interface “eno16777736“.

[root@server ~]# ip a

1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:76:96:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.10/24 brd 192.168.12.255 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe76:96a8/64 scope link
       valid_lft forever preferred_lft forever

DHCP Mode:

In this mode, system will get ipadress from DHCP servers. Lets check the available interfaces on your system.

[root@server ~]# ip a

1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:76:96:a8 brd ff:ff:ff:ff:ff:ff

From the above output, you can see my system has two interface “lo” and “eno16777736“. Depends on hardware, name of the interface will change.

Now, we will set interface “eno16777736” to get an IP address from DHCP server. To do that, go to /etc/sysconfig/network-scripts/ directory, there you will find a file “ifcfg-<interfacename>“. As per above output, my system has a file “ifcfg-eno16777736“.

Edit the “ifcfg-eno16777736” file.

# cd /etc/sysconfig/network-scripts/

# vi ifcfg-eno16777736

HWADDR=00:0C:29:76:96:A8
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=e5a5d8e9-b5d4-4b5e-bd1e-6ebcd0144dfa
ONBOOT=no

Just modify the lines like this.

HWADDR=00:0C:29:76:96:A8
TYPE=Ethernet
BOOTPROTO=dhcp ##Assigning IP from DHCP
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=e5a5d8e9-b5d4-4b5e-bd1e-6ebcd0144dfa
ONBOOT=yes  ## Interface enabled

Restart the network service using below command.

# service network restart

Now you can see the ip address “192.168.12.19” assigned to the interface “eno16777736” using dhcp .

[root@server ~]# ip a

1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:76:96:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.19/24 brd 192.168.12.255 scope global dynamic eno16777736
       valid_lft 1743sec preferred_lft 1743sec
    inet6 fe80::20c:29ff:fe76:96a8/64 scope link
       valid_lft forever preferred_lft forever

Thats All.

POSTS YOU MAY LIKE -:)

Share This Post

Shares