Static IP Address on Unix and Redhat Machine
Posted by hsukumar on 15/04/2008
In Unix it is possible to directly change the IP address, netmask, and broadcast address, using the ifconfig command like s
# ifconfig eth0 143.229.xxx.yyy netmask 255.255.255.0
# ifconfig eth0 broadcast 143.229.xxx.255
Here xxx represents the subnet, and depends on which dorm or building you are in, and yyy is unique to your computer. The netmask is used to determine what part of a network address is considered local – The part of the address which is zero in the netmask is the local part of the address.
To send to an address outside of the local subnet reqires that the packets be sent to a gateway host or router. In Unix the default route (gateway) is set with the route command
# route add -net default gw 143.229.xxx.1 eth0
(The syntax of the route command is slightly different on Mac OS X, but the idea is the same.) You can verify these settings by giving the ifconfig or route commands with no arguments, in which case the network interface status or routing tables are printed to the screen.
These changes will go away after the next reboot. You can make permanent changes by editing the appropriate configuration files. Red Hat Linux keeps the network settings in the file /etc/sysconfig/network. This is also where the host name is kept. The file should look something like:
NETWORKING=yes HOSTNAME=hsukumar BOOTPROTO=static IPADDR=100.200.300.400 NETMASK=255.255.255.192 GATEWAY=100.200.300.500Figure 1: The file /etc/sysconfig/network for a static IP address.
You can edit this file with your favourite editor (eg. emacs) to change the IP address, netmask, gateway, or host name, and the changes will take effect the next time the network services are restarted.
Also change the file The file /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 ONBOOT=yes BOOTPROTO=DHCP
where BOOTPROTO=static
save the file
and type the following command
$ service network restart
All done thats it…
Jacob Varghese said
Static IP Address on Unix and Redhat Machine
Simple but very clear instructions. Keep up the good work