CentOS Network Settings

Static IP

To set a static IP start by editing the device file in sysconfig. In this example, we’re assigning IP address of 192.168.7.2 to eth0. Then we will set the hostname and gateway, and then DNS servers.

Set IP in Network Device File
Right now you probably have some information in there maybe for DHCP.

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

We want to get rid of all that and make the whole file look like this:

DEVICE="eth0"
BOOTPROTO="none"
HWADDR="08:00:27:88:3B:4A"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=192.168.7.2


Set Hostname & Gateway
Next we can set the gateway and a hostname in /etc/sysconfig/network, in my example, i’m setting the gateway to 192.168.7.1 and the hostname to puppet.example.motorrobot.net
Note: setting GATEWAY= here sets the gateway across all interfaces, you can also choose to set GATEWAY in the device file if it’s specific to that device.

vi /etc/sysconfig/network

We want to get rid of all that and make the whole file look like this:

NETWORKING=yes
HOSTNAME=puppet.example.motorrobot.net
GATEWAY=192.168.7.1

Set DNS in CentOS

Next we set DNS in /etc/resolv.conf, in my example my DNS is at 192.168.7.1. Note this creates the file as one single line with a single nameserver listed. You can add additional ones below as well as things like the search path. 

echo "nameserver 192.168.7.1" > /etc/resolv.conf
(Comments)

Comments