Saturday, July 16, 2011

How to Set the Static IP In Command Line

RED Hat / Fedora Linux :

     Login as root, Change the directory to /etc/sysconfig/network-scripts/

# cd /etc/sysconfig/network-scripts/

      Here you can find the Ethernet configuration file such as ifcfg-eth0, ifcfg-eth1.Using any one of the favorite editor, you can edit or append the Ethernet configuration file.

# vim ifcfg-eth0

Edit/Append as follow:

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:30:48:57:A6:2M
IPADDR=192.168.0.2
NETMASK=255.255.255.0
ONBOOT=yes

     After modification , save and close the file.

To Set Gateway and Hostname :

   Change to the directory /etc/sysconfig/ and edit network file.

#vim network

NETWORKING=yes
HOSTNAME=host.example.com
GATEWAY=192.168.0.1

To Set Nameserver :

    Change the directory /etc/ and edit the resolv.conf file

#vim resolv.conf

search dns-search-path
nameseever dns1.ip-address
nameserver dns2.ip-address

    After updating the ip-address, gateway and the nameserver restart the network service.

# /etc/init.d/network restart

Debian / Ubuntu Linux :


   Main Network Configuration Files is /etc/network/interfaces. Using any one of the favorite editor, you can edit or append the Ethernet configuration file.

#vim /etc/network/interfaces

Edit/Append as follow:

iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254

     After modification , save and close the file

To Set Nameserver :

   Change the directory /etc/ and edit the resolv.conf file

#vim resolv.conf

search dns-search-path
nameseever dns1.ip-address
nameserver dns2.ip-address

    After updating the ip-address, gateway and the nameserver restart the network service.

#/etc/init.d/networking restart