By Sebastiaan de Jonge, published on Friday, August 3, 2012 at 15:00

This guide gives a quick description on how to modify your local CentOS server so that it will have a fixed address within your network.

Modifying the interface configuration

The interface configurations are located under /etc/sysconfig/network-scripts/. In my example my interface is called eth0. So I will edit my ifcfg-eth0 file with my favorite editor:

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

And change the contents inside to the following:

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:00:00:00:00:00
ONBOOT=yes
IPADDR=192.168.1.111
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

Adding DNS support

Not quite there yet, for now (after rebooting) you will be connected to the network with the specified IP address, however you will not be able to perform any DNS lookups yet (you will, but they will bounce back). We still need to add our router (or any other nameservers) to our local list of nameservers.

Simply edit the resolv.conf and add your router/DNS servers like so:

vi /etc/resolv.conf

nameserver 192.168.1.1

All done

Now just reboot and your machine will be connected to the local network with the specified IP-address.

If you are using an address that is in a range that might be assigned by your router, you should try to exclude it on the router to prevent any possible IP conflicts.

Comments

Blod
Blod - Saturday, September 6, 2014 at 12:47

Thanks

nmtui
nmtui - Friday, December 4, 2015 at 08:52

CentOS has also tool called 'nmtui'. That's the easy way for those who doesn't like text file editing.