To set up a single Static IP on Centos 6/RHEL do the following
(This assumes you have an existing connection 'eth0')
Install iproute2 tools
$ sudo yum -y install iproute
First rename your existing file and get some information from it
$ sudo su
# cd /etc/sysconfig/network-scripts/
# mv ifcfg-eth0 ifcfg-eth0.bak
# cat ifcfg-eth0.bak
Echo the HWADDR and UUID into your new ifcfg-eth0 file
# echo HWADDR="00:02:44:4B:52:D8" UUID="2609446d-e228-4600-ae9c-8230c1c3d7d3" > ifcfg-eth0
You can use the below commands to view the routing table.
$ route -n
$ netstat -nr
Add the lines below to complete the file
(Drop the UUID to the next line)
# vi ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
IPADDR=192.168.0.100
NETMASK=255.255.255.0
NETWORK=192.168.0.0
GATEWAY=192.168.0.1
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
Save the file
Replace the four network values with your own, you can get all the information from the two commands above, this assumes you will know the static ip address range of your own router for the IPADDR.
(NETWORK will be under 'Destination', GATEWAY will be under 'Gateway' and NETMASK will be under 'Genmask' using either route -n or netstat -nr commands)
# service network restart
To relaunch the new configuration
$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:02:44:4B:52:D8
inet addr:192.168.0.100 Bcast:192.168.0.255
Mask:255.255.255.0
inet6 addr: fe80::202:44ff:fe4b:52d8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6071 errors:0 dropped:0 overruns:0 frame:0
TX packets:6899 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3804377 (3.6 MiB) TX bytes:1416715 (1.3 MiB)
Interrupt:18 Base address:0x8000
Some setups may require a reboot
See also a Static IP with a Network Bridge.
Labels: Centos 6, RHEL, Static IP