CentOS 7 - Configure Static IP
In order to set a static IP, open /etc/sysconfig/network-scripts/ifcfg-[interface name]
in your favourite editor. You should see contents similar to below.
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=enp0s3 UUID=6be86097-6e4f-455e-a3c6-02fbcbae3395 DEVICE=enp0s3 ONBOOT=yes
Change BOOTPROTO
to static
, and add the following items underneath it.
IPADDR=(IP address)
NETMASK=(netmask)
GATEWAY=(IP of gateway)
DNS1=(IP of DNS server)
DNS2
as a backup DNS if you desire.
Your file should now look something like below:
TYPE=Ethernet BOOTPROTO=static IPADDR=192.168.1.45 NETMASK=255.255.0.0 GATEWAY=192.168.1.1 DNS1=192.168.1.2 NM_CONTROLLED=no 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=enp0s3 UUID=6be86097-6e4f-455e-a3c6-02fbcbae3395 DEVICE=enp0s3 ONBOOT=yes
After making the change, you will need to restart the network service for it to apply:
sudo systemctl restart network.service
References
- Nixcraft - CentOS / RHEL 7 Restart / Stop / Start Networking Command
- Ask Xmodulo - How to configure a static IP address on CentOS 7
Last updated: 16th August 2018
First published: 16th August 2018
First published: 16th August 2018