Static IP + DNS settings in CentOS 6

published on in category Linux , Tags: CentOS Network Static

Table of contents

This one seemed easier then it was in the end ;-) Here’s how it works…

Caution: I assume you’re using eth0 as your network interface!

First off, edit /etc/sysconfig/network-scripts/ifcfg-eth0 to include these entries:

DEVICE=eth0
HWADDR="enter your mac address here"
NETWORK=192.168.0.0
BROADCAST=192.168.0.255
NETMASK=255.255.255.0
IPADDR=192.168.0.112
USERCTL=no

Don’t forget to replace the values above to match your actual network configuration. After restarting network services neither the default gateway nor DNS servers are recognized, resulting in a non-usable network. To fix this, add the following contents to /etc/resolv.conf (this file didn’t exist on my installation, so you might have to create it before):

search mycooldomainname.local
domain mycooldomainname.local
nameserver 192.168.0.1

The domain is optional and must not be supplied. Don’t forget to change the nameserver item to match your actual DNS IP address (if you don’t have a separate DNS server you might also use your router’s IP address, because they usually also act as a DNS proxy). Last but not least add a proper gateway (your router by default) to /etc/sysconfig/network:

NETWORKING=yes
HOSTNAME=mycoolhost.mycooldomainname.local
GATEWAY=192.168.0.1

Be sure to get your gateway IP address right. Afterwards just restart the networking service:

service network restart

Now you should have access to the internet which you might verify by pinging google: ping google.de.