Thursday, April 25, 2013

Assign IP Address and Gateway in Linux from Command Line

if config command is used to assign the ip address to a lan card from the command or from the terminal.

Syntax :

 # ifconfig [-v] [-a] [-s]  [interface]

Options :
  • -a :    display all interfaces which are currently available, even if down
  • -s :    display a short list (like netstat -i)
  • -v :   be more verbose for some error conditions
interface : The name of the interface.  This is usually a driver name followed by a unit number, for example eth0 for  the  first Ethernet interface. If your kernel supports alias interfaces, you can specify them with eth0:0 for the first alias of eth0. One can use them to assign a second address. To delete an alias interface use ifconfig eth0:0 down.


Example :

Below command is used to assign ip

# ifconfig eth0   netmask   up

Below command is used to check the ip address of eth0 lan card.

# ifconfig  eth0

Command To check the Default Gateway

# route  -n

Commands To  add/change the gateway

# route  del  default gw                                                 // delete the default gateway
# route add default gw             // command to add default gateway

No comments:

Post a Comment