Problem
You just finished an install of CentOS 7 and need it to be networked with a static address
Solution
Verify if there is an IP address (from DHCP) using the following command
ip addr
Check the permissions on the interface config file (interface will vary ifcfg-ens101 in my case)
ls -l /etc/sysconfig/network-scripts/ifcfg-ens101
If its read only update the permissions as required
sudo chmod 777 /etc/sysconfig/network-scripts/ifcfg-ens101
Edit the interface
vi /etc/sysconfig/network-scripts/ifcfg-ens101
Edit/add the following fields
HWADDR=00:01:02:03:04:05
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPADDR=192.168.0.100
NETMASK=255.255.255.0
NM_CONTROLLED=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=abc12300-abc1-abc1-1234-abc123abc123
ONBOOT=yes
If you had updated the permissions previously, lower as per your requirements e.g.
sudo chmod 766 /etc/sysconfig/network-scripts/ifcfg-ens101
Now let’s configure the default gateway
vi /etc/sysconfig/network
Add the following or edit as required
NETWORKING=yes
HOSTNAME=MyCentOS
GATEWAY=192.168.0.1
While we are at it let’s update the DNS entries
vi /etc/resolv.conf
Use the nameserver command to add dns servers to look up e.g.
nameserver 192.168.0.2 – assuming that .2 is your internal dns
nameserver 8.8.8.8
nameserver 8.8.4.4
One more command, restart the network interfaces
/etc/init.d/network restart
Test by reviewing the interface settings
ip addr
And by issuing a ping command e.g.
ping 8.8.8.8
Tested Platform
CentOS 7
Hits: 1595
One comment