Friday, August 5, 2016

Static IP on CentOS 7

After a minimal install of CentOS 7 you can change the ifcg-enp0s3 file using vi. To do so, type the following command in the prompt: vi /etc/sysconfig/network-scripts/ifcfg-enp0s3


Here is an example of the file using 192.168.1.10 as the static IP address.

TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="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=”Long string of characters”
DEVICE="enp0s3"
ONBOOT="yes"
HWADDR=”MAC ADDRESS”
IPADDR=192.168.1.10
PREFIX=24
GATEWAY=192.168.1.1
DNS=192.168.1.1

Save the file by pressing CTRL, and then type wq. This will save the file and quit the editor. Afterwards, you'll need to restart the networking service by typing the following command:

service network restart

Now your CentOS 7 machine has a static IP address and you can remote in via SSH with Putty or from the terminal of another Linux machine.