How to Configure a Static IP address on CentOS/RHEL 7
This post explains how a static IP address can be set on CentOS/RHEL 7. We can configure the static ip address in /etc/sysconfig/network-scripts/* by setting the properties in the /etc/sysconfig/network-scripts/ifcfg-[interface] file. Here [interface] is the interface of your choice to which you want to assign an IP address.
Below are basic configuration instructions to setup a static IP address on CentOS/RHEL 7.
1. First, list your network interfaces with ip command:
# ip add show
Make a note of network interface you would like to set with static IP address.
2. Next, locate a corresponding script to the network interface name. In our case this is enp0s3 located at /etc/sysconfig/network-scripts/ifcfg-enp0s3.
3. Open this file and enter the following information. Note that your HWADDR,DEVICE,UUID will be different:
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 DEVICE="enp0s3" NETBOOT="yes" HWADDR="<mac>" TYPE="Ethernet" BOOTPROTO="none" NAME="enp0s3" UUID="<uuid>" ONBOOT="yes" IPADDR="10.1.XX.110" NETMASK="255.0.XX.0" GATEWAY="10.1.XX.1"</uuid></mac>
4. The above will set our enp0s3 network interface with static IP address 10.1.XX.110. Once you have made the necessary changes restart the system networking using below command:
# systemctl restart network
5. Confirm that your IP address has been updated:
# ip addr show 1: lo: mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether <mac> brd ff:ff:ff:ff:ff:ff inet 10.1.XX.110/8 brd 10.255.XX.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe15:38b7/64 scope link valid_lft forever preferred_lft forever</mac>