How to setup network on Centos 7

After installing Centos 7, you might find that you can’t connect to the network on that machine. This happens because Ethernet interfaces are not enabled by default. This guide will help you setup network on Centos 7.

This guide contains network configuration steps in both GUI and command mode.

Setup Network on Centos 7

At the command prompt type

nmcli d

which will give you a quick identification of Ethernet cards installed on your machine

Setup-network-on-centos-7-check

Here we have 2 interfaces named “enp0s17” and “enp0s18“. It might be different in your case however.

Setup GUI Mode

Recommended for beginners

Step 1

Type in this command

nmtui

to open network manager and press enter after choosing “edit  a connection” (use tab for choosing options)

Setup-network-on-centos-7

Step 2

Now you can see all network interfaces, choose one and click “Edit

Setup-network-on-centos-7-1

DHCP Configuration

Step 3

for dhcp,

  1. Choose “Automatic” in IPv4 CONFIGURATION.
  2. Choose Automatic connect check box.
  3. Press Ok and quit Network manager.

Setup-network-on-centos-7-2

Now restart network services by typing this command

systemctl restart network

Now your server will get an IP from DHCP

Step 4

For manual IP address,
1. Choose “Manual” in IPv4 CONFIGURATION.
2. Add IP Address with Subnet , Gateway and DNS server ( Refer below image ).
3. Choose Automatic Connect check box.
4. Press OK and quit Network manager.

Setup-network-on-centos-7-3

Now restart network services by typing this command

systemctl restart network

Now your server will have a static IP.

Command Mode

Step 1

Network interface config files are located in /etc/sysconfig/network-scripts/ directory. Open ifcfg-enp0s17 file ( For interface enp0s17 ) and you can see the content like below.

[root@krizna ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s17
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s17
UUID=7f1aff2d-b154-4436-9497-e3a4dedddcef
ONBOOT=no
HWADDR=00:0C:29:A1:B5:D6
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

DHCP Configuration

Step 2

For DHCP
Find the below lines in config File.

BOOTPROTO=none
ONBOOT=no

and replace with

BOOTPROTO=dhcp
ONBOOT=yes

Now Restart network service by typing below command.

systemctl restart network

Now your server will get IP Address from DHCP

» Static configuration

Step 3 » For Static IP.
Find the below lines in config File.

BOOTPROTO=none
ONBOOT=no

and replace with

BOOTPROTO=static
ONBOOT=yes

And add the below lines at the end of the file.

IPADDR=172.27.0.32
NETMASK=255.255.255.0
GATEWAY=172.27.0.1
DNS1=172.27.0.5

File will look like below after changes.

TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s17
UUID=f0c5b37d-299a-43cb-b74b-618bb252d129
ONBOOT=yes
HWADDR=00:0C:29:A1:B5:CC
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.5

Now Restart network service by typing below command.

systemctl restart network

Now Interface will have static IP.
Additionally you can use /etc/sysconfig/network file for hostname and DNS .

HOSTNAME=server.krizna.com
DNS1=192.168.1.5
DNS2=8.8.8.8
SEARCH=krizna.com

I hope this helps anybody reading. Have a great day!

Leave a Reply

Your email address will not be published. Required fields are marked *