How to configure IP's On Centos 7?
Publisher: Psychz Networks, February 05,2020CentOS 7 uses NetworkManager daemon to manage primary network connection and other network interfaces, like Ethernet, WiFi, etc. This tool is easy to use and makes network configuration and operations as painless as possible. In the following article, we will configure a network interface using 'ifcfg' files located in /etc/sysconfig/network-scripts/ directory in a CentOS 7. NetworkManager is a software utility that aims to simplify the use of computer networks. NetworkManager is available for Linux kernel-based and other Unix-like operating systems.
In the following steps we will learn how to configure IPs on CentOS 7 using NetworkManager for both IPv4 and IPv6. Following are the steps covered
Steps to configure IPv4
Step 1
Open and edit the network configuration file for (eth0 or eth1) an editor to assign IP Address to eth0 or eth1 interface as follows.
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Output:
TYPE=Ethernet
BOOTPROTO=none
# Server IP #
IPADDR=192.XXX.XX.XXX
# Subnet #
PREFIX=24
# Set default gateway IP #
GATEWAY=192.XXX.XX.XXX
# Set dns servers #
DNS1=8.8.8.8
DNS2=8.8.4.4
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
The lines marked in bold are the important ones as you will have to modify them as per your needs.
Note: In case you find no file under /etc/sysconfig/network-scripts/ we need to create one. Create a file named /etc/sysconfig/network-scripts/ifcfg-eth0 using a VI editor and add the above content in the file. Press Esc and then :wq (to save and exit)
Step 2
Now, Restart network service
#
systemctl
restart network
Let us now verify the IP settings
#
ip
a s eth0
Output
link/ether 00:08:a2:0a:ba:b8 brd ff:ff:ff:ff:ff:ff
inet 192.XXX.XX.XX/24 brd 192.XXX.X.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::208:a2ff:fe0a:bab8/64 scope link
valid_lft forever preferred_lft forever
Step 3
Verifying DNS server settings
# cat /etc/resolv.conf
Output
nameserver 8.8.8.8
Nameserver 8.8.4.4
The last step to verify that you have successfully configured the network on your CentOS machine is to check if you can reach any site. You can simply use the "Ping" command followed by the web address (e.g. google.com) and you will get the results
Steps to configure IPv6
IPv6 possess certain features that are superior to IPv4 address in terms of efficient routing, directed data flows, simplified network configuration, security and much more.
Following are the steps to assign IPv6 address on your server
Step 1
You need to edit sysctl.conf file. Using VIM editor open the file to edit it.
# vim /etc/sysctl.conf
Add the following two lines at the end of the file
net.ipv6.conf.all.disable_ipv6 = 0
Save and exit using "esc + :wq"
Step 2
Edit the network file using VIM editor which is located under /etc/sysconfig/
# vim /etc/sysconfig/network
Add the following line at the end of the file.
Save and exit using "esc + :wq"
Step 3
Now we will edit the ifcfg-eth0 file under the path /etc/sysconfig/network-scripts/
# vim sysconfig/network-scripts/ifcfg-eth0
Append the following lines to the file,
IPV6ADDR=2001:0db8:ABCD:XXXX:XXXX:XXXX:XXXX:XXXX
IPV6_DEFAULTGW=2001:0db8:ABCD:XXXX:XXXX:XXXX:XXXX:XXXX
Save and exit using "esc + :wq"
Note: Kindly replace the IPv6 address and default gateway with the one provided to you.
Step 4
Now you may restart the network service to bring all the changes into effect
# /etc/init.d/network/restart
You can test the connection by pinging any website (e.g. www.google.com)