To be more specific I'm referring to RHEL (Red Hat Enterprise Linux) 5.5, the only version I could test.
SHORT ANSWER
You have to edit the proper network file:
vi /etc/sysconfig/network-scripts/ifcfg-ethX
where X is the interface number (usually you'll have ifcfg-eth0 or ifcfg-eth1).
A working situation should be something like this (replace IP addresses with your own):
DEVICE=eth0
BOOTPROTO=none # in some places I found "static", but with "none" it works
ONBOOT=yes
HWADDR=00:00:00:00:00:00 # you should already have a MAC address, so leave that one
# if you don't, I think you can simply delete this field
NETMASK=255.255.255.0
IPADDR=192.168.0.10
GATEWAY=192.168.0.254
Beware to write your correct IP addresses and, if you're remotely connected, be sure to have another way to access you system. Errors in this file could shut you out of your server, for they will break your network connection.
After carefully checking you configuration at least 3 times, restart your networking service:
/etc/init.d/network restart
Now you should have a static IP address and a working connection.
LONG ANSWER
This time the "long answer" is just a collection of various tips regarding networking on RHEL.
When I had a problem and I had to search how to configure a static IP address in RHEL, I found a post (that I won't link) with a configuration file where there was no default gateway (that is, "GATEWAY=" line was missing). I didn't receive any error after restarting network service, but then I couldn't connect to any IP address. Mind you, I was connected directly to the machine. If I was connected via, for example, SSH, I would not have been able to access to any service (including SSH) hosted on that machine.
The reason is that, not setting any default gateway, RHEL couldn't create the right routes, so traffic simply wasn't leaving the machine.
If you want the exact opposite of this post (which is to use DHCP to assign IP addresses), delete from the above configuration the NETMASK, IPADDR and GATEWAY lines and edit the BOOTPROTO line from none (or static) to dhcp. The new configuration file should look something like this:
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:00:00:00:00:00 # if you already have this field configured.
then again, restart your network manager:
/etc/init.d/network restart
Last but not least, if you set a static IP address, don't forget to set one or more static DNS servers! Otherwise ping google.com won't find any server called google.com and you'll think the world is about to end!! ;)
vi /etc/resolv.conf
If there isn't anything already in there, put something like the following, editing the fields according to your needs:
search bigbrus # this should be your ISP; if you're behind a firewall I think it doesn't matter
nameserver 8.8.8.8 # put here your favourite DNS IP address
nameserver 8.8.4.4 # these two are Google's DNS severs
Then save your file, and restart network service:
/etc/init.d/network restart
USEFUL LINKS
RELATED POSTS
Labels: bash, linux