Friday 6 January 2012

How to Setup Static or Dynamic IP Address in Centos

After centos operting system installation, i can't able to communicate another machine. At that time i checked and found my machine network interface (eth0) down. I got my network interface information using "ifconfig" command

            [root@localhost ~]# ifconfig

                   lo          Link encap:Local Loopback  
                                inet addr:127.0.0.1  Mask:255.0.0.0
                                inet6 addr: ::1/128 Scope:Host
                                UP LOOPBACK RUNNING  MTU:16436  Metric:1
                                RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                                TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                                collisions:0 txqueuelen:0 
                                RX bytes:0 (0.0 MiB)  TX bytes:0 (0.0 MiB)

Above result is showing network interface down. So i used below command to up the interface.

             [root@localhost ~]#  ifup  eth0

After that again i checked. It was up

              [root@localhost ~]# ifconfig

                    eth0      Link encap:Ethernet  HWaddr 10:78:D2:54:19:BD  
                                 inet6 addr: fe80::1278:d2ff:fe54:19bd/64 Scope:Link
                                 UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
                                RX packets:1055 errors:0 dropped:0 overruns:0 frame:0
                                TX packets:4 errors:0 dropped:0 overruns:0 carrier:5
                                collisions:0 txqueuelen:1000 
                                RX bytes:88232 (86.1KiB)  TX bytes:328 (328.0 b)

                    lo          Link encap:Local Loopback  
                                inet addr:127.0.0.1  Mask:255.0.0.0
                                inet6 addr: ::1/128 Scope:Host
                                UP LOOPBACK RUNNING  MTU:16436  Metric:1
                                RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                                TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                                collisions:0 txqueuelen:0 
                                RX bytes:0 (0.0 MiB)  TX bytes:0 (0.0 MiB)

I had tried two methods for setting up ip address,

    1. DHCP IP Address
    2. Static IP Address

Network interface configuration file location "/etc/sysconfig/network-scripts/ifcfg-eth0 "

Configure Dynamic IP Address :


 First i configured dynamic ip address for my machine. This steps i used for that.
        

         [root@localhost ~]# vim  /etc/sysconfig/network-scripts/ifcfg-eth0

                                  DEVICE="eth0"
                                  BOOTPROTO="dhcp"
                                  HWADDR=10:78:D2:54:19:BD
                                  NM_CONTROLLED="yes"
                                  ONBOOT="yes"
                                  TYPE="Ethernet"
                                  UUID="6b03d1a2-8bb1-4d7b-bd03-8a2e2b4acccf"

                      : wq

After that i restarted the network service

         [root@localhost ~]#  /etc/init.d/network  restart

Configure Static IP Address :


Second i tried static ip address for my machine. This steps i used for that

        [root@localhost ~]# vim  /etc/sysconfig/network-scripts/ifcfg-eth0

                                  DEVICE="eth0"
                                  BOOTPROTO="static"
                                  HWADDR=10:78:D2:54:19:BD
                                  NM_CONTROLLED="yes"
                                  ONBOOT="yes"
                                  TYPE="Ethernet"
                                  UUID="6b03d1a2-8bb1-4d7b-bd03-8a2e2b4acccf"
                                  IPADDR=192.168.0.100
                                  NETMASK=255.255.255.0
                                
                              :wq  


After that i restarted the network service

             [root@localhost ~]#  /etc/init.d/network  restart


No comments:

Post a Comment