LLI Wiki — My Digital Knowledge Base

CentOS 6: change IP, gateway and DNS

Change the IP address, gateway and DNS servers through the CentOS 6 network configuration files.

How to change the IP address, gateway and DNS servers on CentOS 6 by editing the network configuration files.

IP address and gateway

Open the interface configuration file:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Typical content (documentation values):

DEVICE=eth0
TYPE=Ethernet
UUID=00000000-0000-0000-0000-000000000000
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.0.2.20
PREFIX=26
GATEWAY=192.0.2.1
DNS1=192.0.2.10
DOMAIN=example.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=00:00:00:00:00:00

The two main values to change are IPADDR (IP address) and GATEWAY (default gateway).

Gateway (global setting)

The gateway can also be set in /etc/sysconfig/network:

vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=sqlserver01
GATEWAY=192.0.2.1

DNS servers

Edit /etc/resolv.conf:

vi /etc/resolv.conf
nameserver 192.0.2.10
nameserver 192.0.2.11

Notes

Mastodon LLIMastodon SocialFosstodon