Network configuration on CentOS 7 is made automatic and simple through the use of Network Manager. It manages network interfaces like Ethernet, WiFi, and Mobile Broadband devices, in addition to the primary network connection. Here you are going to quickly learn how to configure a network interface in etc/sysconfig/network-scripts/ directory using ifcfg files.
The first step is to create this file /etc/sysconfig/network-scripts/ifcfg-eth0.
Here is how to step forward:
1)DEVICE=eth0 2)BOOTPROTO=none 3)ONBOOT=yes 4)PREFIX=24 5)IPADDR=192.168.2.203 6)Restart network service: systemctl restart network
In order to list network interfaces, type this command:
# ip a
# nmcli -p dev
You can see below the DHCP typical configuration for eth0 that is stored in /etc/sysconfig/network-scripts/ifcfg-eth0 file
DEVICE="eth0" ONBOOT=yes NETBOOT=yes UUID="41171a6f-bce1-44de-8a6e-cf5e782f8bd6" IPV6INIT=yes BOOTPROTO=dhcp HWADDR="00:08:a2:0a:ba:b8" TYPE=Ethernet NAME="eth0"
Configuring an eth0 interface
There are two ways for this configuration. First Method In this method, you need to edit or create a new file by the name of ifcfg-eth0 in /etc/sysconfig/network-scripts/ directory
Here is how to do it:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
For static IP configuration, update or edit as the following:
HWADDR=00:08:A2:0A:BA:B8 TYPE=Ethernet BOOTPROTO=none # Server IP # IPADDR=192.168.2.203 # Subnet # PREFIX=24 # Set default gateway IP # GATEWAY=192.168.2.254 # Set dns servers # DNS1=192.168.2.254 DNS2=220.127.116.11 DNS3=18.104.22.168 DEFROUTE=yes IPV4_FAILURE_FATAL=no # Disable ipv6 # IPV6INIT=no NAME=eth0 # This is system specific and can be created using 'uuidgen eth0' command # UUID=41171a6f-bce1-44de-8a6e-cf5e782f8bd6 DEVICE=eth0 ONBOOT=yes
Save and close the file. The system will automatically calculate the network and broadcast address.
Restart the network service using:
# systemctl restart network
Verify the settings
# ip a s eth0
# ip r
# cat /etc/resolv.conf
# ping -c 3 cyberciti.biz # ping -c 4 google.com
The second method for configuring eth0 interface is the use of Network Manager nmtui command is used:
# nmtui edit eth0