Jump to content


- - - - -

Setting up a static IP


The following steps will guide you through setting up your server to use a static IP address on CentOS.

Assuming the network interface is supported and detected under CentOS, you will find that the configuration files required to set the IP address can be found under /etc/sysconfig/network-scripts.

The files to look for are ifcfg-eth# where # is the network interface number, starting from 0.

This example will assume that you want to set up the static IP address on the first network interface.
The following steps will guide you through setting up your server to use a static IP address on CentOS.

Assuming the network interface is supported and detected under CentOS, you will find that the configuration files required to set the IP address can be found under /etc/sysconfig/network-scripts.

The files to look for are ifcfg-eth# where # is the network interface number, starting from 0.

This example will assume that you want to set up the static IP address on the first network interface.

Open up the /etc/sysconfig/network-scripts/ifcfg-eth0 file in your favorite editor. This guide will be using the “nano” editor, but you can use “vi” or another editor.

Make sure you are logged in as “root”, or a user with root privileges I will be using
nano /etc/sysconfig/network-scripts/ifcfg-eth0


You should see the lines similar to the following in the editor.
DEVICE="eth0"
HWADDR="00:AA:BB:CC:DD:EE"
NM_CONTROLLED="yes"
ONBOOT="no"


Most of the lines in this file will be changing, so your best option is to remove all the lines except the first one, and copy the example format from the example below.

If you dont want to delete the lines, simply comment them out. This allows you to change it back easily at a later date if you want to. The # character at the beginning of the line indicates that it is commented out, and will be ignored.

Make sure you change the relevant settings to suit your network.
DEVICE="eth0"
#HWADDR="00:AA:BB:CC:DD:EE"
#NM_CONTROLLED="yes"
#ONBOOT="no"

NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=192.168.0.10
NETMASK=255.255.255.0
GATEWAY=192.168.0.1

Once you have finished with the changes to the file, save and quit the editor.

You will also need to set up the DNS nameserver settings manually. These are stored in the /etc/resolv.conf file.

Open this file in your editor.
nano /etc/resolv.conf

you will want at least 1 nameserver set up in this file. If one already exists, and is valid, great. If not, add one or more nameserver records in the format below.
nameserver 192.168.0.1

Depending on your setup, this could be your router’s IP, your ISP’s DNS server IP, or a 3rd party’s DNS server, such as Google’s (8.8.8.8 and 8.8.4.4), or OpenDNS.

Save and exit the editor.

To activate the changes you will need to reboot the PC, or simply restart networking (recommended).
etc/init.d/network restart
or
service network restart

To verify the setting have taken place run
ifconfig eth0


0 Comments