How to change DHCP to static

I changed my IP from DHCP to static by editing configuration file. And guess what? Sendmail daemon can't be started. Ping can't work from the server and to the server. The reason? I used MAC address of eth1 for eth0. Damn.

These instruction only work for Redhat and Redhat-based distro.

1. Edit /etc/sysconfig/network-script/ifcfg-ethX. You can replace X with your network card number. Your current file will look like this

DEVICE=ethX
BOOTPROTO=dhcp
HWADDR=xx:xx:xx:xx:xx:xx
ONBOOT=yes
DHCP_HOSTNAME=yourmachinename.yourdomainname.suffix

Change it into

DEVICE=ethX
BOOTPROTO=static
HWADDR=xx:xx:xx:xx:xx:xx <--please don't change this
IPADDR=your.ip.address
NETMASK=your.net.mask
NETWORK=your.network.address
ONBOOT=yes <--please don't change this

If you can't calculate your network address, please asked your admin

2. Edit /etc/sysconfig/network. Your current file will look like this

NETWORKING=yes
NETWORKING_IPv6=no
HOSTNAME=yourmachinename.yourdomainname.suffix

Just add another line

GATEWAY=your.gateway.IPAddress

3. Restart your network.

$ /etc/init.d/network restart

4. Try ping to somewhere else. If you get a reply, congratulation, you have successfully change your IP address from DHCP to static by using configuration files.

No comments: