Friday, July 3, 2009

Set a static IP in CentOS/RHEL

A few weeks ago I wrote about how to set a static IP address in Ubuntu and now I am posting about how to do it in CentOS/RHEL. Unlike in Ubuntu, in CentOS, there is a separate config file for each network adapter. These files are located in "/etc/sysconfig/network-scripts/". So, for example, the config file for interface "eth0" is located at "/etc/sysconfig/network-scripts/ifcfg-eth0". If the adapter is configured to use DHCP, the contents of the file should look something like this:
# [Name of manufacturer and model of network adapter]
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:xx:xx:xx:xx:xx
ONBOOT=yes
DHCP_HOSTNAME=[hostname]
To convert this over to using a static IP address instead, you will need to make some changes and add a bunch of information so that it looks more like this:
# [Name of manufacturer and model of network adapter]
DEVICE=eth0
BOOTPROTO=none
BROADCAST=192.168.1.255
HWADDR=00:xx:xx:xx:xx:xx
IPADDR=192.168.1.24
IPV6INIT=no
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
GATEWAY=192.168.1.1
TYPE=Ethernet
PEERDNS=yes
USERCTL=no
This assumes you are setting the interface to use an IP address of 192.168.1.24 and a default gateway of 192.168.1.1. In order for the changes to take effect you will need to restart the networking daemon. This is accomplished by running either of the following commands as root:
/etc/init.d/network restart
-or-
service network restart
When the interface comes back online it will use the newly configured settings.

6 comments:

  1. Thanks! Helped a noob like me! :)

    ReplyDelete
  2. Does this directive "ONBOOT=yes" make network configuration runing in boot time.

    ReplyDelete
  3. Considerably, this post is really the sweetest on this notable topic. I harmonise with your conclusions and will thirstily look forward to your incoming updates. Saying thanks will not just be sufficient, for the phenomenal clarity in your writing. I will directly grab your rss feed to stay informed of any updates. Admirable work and much success in your business dealings!? Please excuse my poor English as it is not my first tongue.

    ReplyDelete
  4. Windows 7 starter... maybe try simple english.. no one talks like that!

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete