Pages

Tuesday, 8 March 2016

Configuring a static / dynamic IP, default route and DNS on CentOS 7

We will firstly setup our interface - to do so we should issue (ifconfig is not included on the core edition):

ip addr

This will return all available interfaces - in our case we are interested in one called:

eno858544

So in order to statically configure the interface we should create (or modify) it's script within networking-scripts directory:

sudo vi /etc/sysconfig/network-scripts/ifcfg-eno858544

and add the following (for minimum config):

TYPE=ethernet
BOOTPROTO=static
IPADDR=1.2.3.4
NETMASK=255.255.255.0
NM_CONTROLLED=no
NAME=eno858544
DEVICE=eno858544 # Points to the block device
ONBOOT=yes # Start interface at boot time? (or after network services restart)

and these extras (optional):

DEFROUTE=yes # Is this interface the default route?
IPV6INIT=yes # Do you want to enable IPv6?
IPV6_AUTOCONF=yes # Should usually be left as yes if you are using IPv6
IPV6_DEFROUTE=yes
IPV4_FAILURE_FATAL=no # Should the interface be disabled if the link goes down?
IPV6_FAILURE_FATAL=no # Should the interface be disabled if the link goes down?

For setting up DHCP we can do something like:

TYPE=ethernet
BOOTPROTO=dhcp
NM_CONTROLLED=no
NAME=eno858544
DEVICE=eno858544 # Points to the block device
ONBOOT=yes # Start interface at boot time? (or after network services restart)
PEERDNS=YES # If you specify DNS1=x.x.x.x  (or are using DHCPO) in your config here you should change this value to 'YES'
PEERROUTES=YES # Should routing information be obtained from the DHCP server?
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

and add the following (optionally):

DEFROUTE=yes # Is this interface the default route?
IPV6INIT=yes # Do you want to enable IPv6?
IPV6_AUTOCONF=yes # Should usually be left as yes if you are using IPv6
IPV6_DEFROUTE=yes
IPV4_FAILURE_FATAL=no # Should the interface be disabled if the link goes down?
IPV6_FAILURE_FATAL=no # Should the interface be disabled if the link goes down?

We should now proceed by setting up our routing - by defining a default gateway:

sudo vi /etc/sysconfig/network

and add something like:

NETWORKING=yes
HOSTNAME=myhostname
GATEWAY=1.2.3.1

ip route default 1.2.3.4 dev eno858544

In order to setup DNS, domain options we can either add an entry globally in /etc/resolv.conf (like most other distros):

sudo vi /etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4
search mydomain.internal

or we can add an entry in our interface init script:

sudo vi /etc/sysconfig/network-scripts/ifcfg-eno858544

DNS1=8.8.8.8
DNS2=8.8.4.4

No comments:

Post a Comment