Assign IP Address and Default gateway in Linux From Command Line
ifconfig command is used to assign the ip address to a lan card from the command or from the terminal.
# ifconfig [-v] [-a] [-s] [interface]
- -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.
Below command used to assign ip
# ifconfig eth0 <ip-address> netmask <yournetmask> 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 <gateway-ipaddress> // command to add default gateway