Centos 7 - How to static ip

From Linux - Help
Jump to navigation Jump to search
Centos 7

A quick guide, how to configure an static ip with Centos 7.

First we need to know witch hardware is used to your internet connection (Ethernet, WIFI, 3G):

 ifconfig # check if eno1, eth1 or wlan1 are up:
In my case, I am using eth0.

Then check the status of your Network Manager and stop the service:

 su -c 'service NetworkManager status'
 su -c 'service NetworkManager stop'

Then you will need to configure the file /etc/sysconfig/network

 su -c 'nano /etc/sysconfig/network'
       NETWORKING=yes
       NETWORKING_IPV6=no
       HOSTNAME=your_hostname
       GATEWAY=your_gateway

Now you will need to configure the script /etc/sysconfig/network-scripts/ifcfg-eno0cd

*eno0cd depends of your hardware, this is for an Ethernet connection, you should check which match your device.

 su -c 'nano /etc/sysconfig/network-scripts/ifcfg-eno0cd'
       DEVICE=your_device
       BOOTPROTO=static
       BROADCAST=your_broadcast
       IPADDR=your_wanted_ip
       NETMASK=your_netmask
       NETWORK=your_network
       DNS1=208.67.222.222 # if you want to use opendns
       DNS2=208.67.220.220 # if you want to use opendns
       ONBOOT=yes

Example of a good configuration for a simple Network:

       DEVICE=eno1
       BOOTPROTO=static
       BROADCAST=192.168.0.255
       IPADDR=192.168.0.78
       NETMASK=255.255.255.0
       NETWORK=192.168.0.0
       DNS1=208.67.222.222
       DNS2=208.67.220.220
       ONBOOT=yes

Now if you want to configure your DNS server, you need to configure /etc/resolv.conf file:

 su -c 'nano /etc/resolv.conf'  
       #Generated by NetworkManager
       nameserver 208.67.222.222
       nameserver 208.67.220.220

Now you can restart the Network Manager services:

 su -c 'service network restart'
 su -c 'init 6' # retart server

Online resources

Centos 7