Thursday, February 23, 2012

how to assignig ip on linux


Assigning IP Address on Linux:

To check IP address:
# ifconfig              >> to see all interfaces
# ifconfig eth0      >> to see specific interface

Required File to Edit:
#vi  /etc/sysconfig/network-scripts/ifcfg-eth0   >> edit ifcfg-eth0 file to add IP detail
#Vi  etc/resolv.conf  >> to add NameServer or dns
# vi /etc/sysconfig/network  >> add GATEWAY & Hostname etc
#vi /etc/hosts    >> To Name Resolv
 
To up/down interfaces:
# ifconfig eth0 up       >> to up eth0
#ifconfig eth0 down  >> to down eth0

Assigning IP Address Temporary on interface: (After restarting this IP address will gone)
# ifconfig eth0 172.16.2.21 netmask 255.255.255.0 up  >> set IP on eth0 interface
# route add default gw 172.16.2.1 eth0  >> set getaway on eth0 interface

Assigning IP Address Permanently on interface:  (For this situation you have to edit mamually and also using netconfig command)

Using netconfig command:
# netconfig   >>(Press Enter Key, Now you get an interface, where you configure IP address). Then
# service network restart (Press Enter Key, that will done)
(N.B. As soon as possible i provide more details screen shot)

Manually Assigning IP address:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0   >> just view the configuration file
#  vi  /etc/sysconfig/network-scripts/ifcfg-eth0   >> edit ifcfg-eth0 file to add IP detail
 
To add default gateway (location - /etc/sysconfig/network)
# vi /etc/sysconfig/network  >> add GATEWAY


To Add NameServer ( /etc/resolv.conf)
Vi  etc/resolv.conf  >> to add NameServer

# services network restart  >> run this command to enable changes .

Now you see the change of "ifcfg-eth0" file. # cat /etc/sysconfig/network-scripts/ifcfg-eth0

 Add Virtual interface address permanently:
#  vi  /etc/sysconfig/network-scripts/ifcfg-eth0:1      >> to create new virtual interface and assign IP
check out the created virtual interface

# services network restart  >> run this command to enable changes .

# cat   /etc/sysconfig/network-scripts/ifcfg-eth0:1      >> to view interface

Some other Ping commands:
#ping 4.2.2.2 -s 2048   >> to ping load
#ping 4.2.2.2 -c 5        >> number of time to ping
#ping 172.168.1.0 -b  >> Broadcast ping 


No comments:

Post a Comment