Monday, August 19

Assign ip address in command mode on Redhat/CentOS 5&6


Assign IP Address in Command Mode:


Log on as root user and change directory to /etc/sysconfig/network-scripts/ to view all available devices.

    # cd /etc/sysconfig/network-scripts/

You need to edit following files:

    /etc/sysconfig/network-scripts/ifcfg-eth0 ( First Ethernet card configuration file)
    /etc/sysconfig/network-scripts/ifcfg-eth1  ( Second Ethernet card configuration file)

To edit/create first NIC file, type command:

    # vi ifcfg-eth0

Append/modify as follows:

    DEVICE=eth0
    BOOTPROTO=static
    DHCPCLASS=
    HWADDR=00:30:48:56:A6:2E
    IPADDR=192.168.1.22
    NETMASK=255.255.255.0
    ONBOOT=yes

Save and close the file. (:wq!)

After that, configure the default gateway (router IP) and hostname in /etc/sysconfig/networkfile:

    # vi /etc/sysconfig/network

Append/modify configuration as follows:

    NETWORKING=yes
    HOSTNAME=opesource
    GATEWAY=192.168.1.1

Save and close the file(:wq!). Restart networking by enter following command:

    # /etc/init.d/network restart

Make sure you have correct DNS server defined in /etc/resolv.conf file:

    # vi /etc/resolv.conf

Setup DNS Server as follows:

    nameserver  8.8.8.8
    nameserver  8.8.4.4

Save and close the file(:wq!). Now you can check(ping) the gateway/other hosts:

     # ping 192.168.1.1          (check network connection)
   
    #ping www.google.com    (check Internet connection )

1 comment:

:: Linux - Legends ::