Configure Static IP for Centos 7

How to configure your default IP as static on Centos 7.

You will need to SSH into the server, and change directory to /etc/sysconfig/network-scripts/

You will need to edit the ifcfg-eth0 file. Keep in mind that your NIC device may have a different name. Check ifconfig before moving forward. Before editing make sure you make a backup of the original file. I typically create a new directory in network scripts call “off”. Then copy the original file to that directory. After that you can edit the file in network scripts. Example of a file is below.

Example ifcfg-eth0 fileā€¦

TYPE=Ethernet
NAME=eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static <<< “Change this line from dhcp to static”
IPADDR=”xxx.xxx.xxx.xxx” <<< “You will need to add this line with the default IP address of your server”
NETMASK=”255.255.255.255″ <<< ” You will need to add this line”
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
LINKDELAY=30
NM_CONTROLLED=no
ONBOOT=yes
IPV6INIT=yes
NETWORKING_IPV6=yes
IPV6_AUTOCONF=yes
DHCPV6C=yes
DHCPV6C_OPTIONS=-nw
ONBOOT=yes
DHCP_HOSTNAME=AD47E10

**save and close the above.

Then you will need to create the below…

vi /etc/sysconfig/network-scripts/route-eth0
10.255.255.1 dev eth0
default via 10.255.255.1 dev eth0

**save and close the above.

/etc/init.d/network restart

Note:

please check with ifconfig -a command to see the Interface name, some times it could be eth0, eth0:1 or eth0, eth1, ens

If both Interfaces eth0, and eth0:x then the route-eth0 is fair enough
If the Interfaces are eth0 and eth1, then create 2 files (route-eth0 and route-eth1), and add the above commad with changing ethx regarding the file name. (eth0 goes with eth0, and eth1 goes with eth1)

Mohammed has written 63 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>