Sunday, April 20, 2008

Basic Linux IP Networking Command 1

Ifconfig - configures interface devices for use. It provides each device with its (IP) address, netmask, and broadcast address.

usage : ifconfig ${DEVICE} ${IPADDR} netmask ${NMASK} broadcast ${BCAST}

example : ifconfig eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255

eth0  Link encap:Ethernet  HWaddr 00:C1:4E:7D:9E:25
      inet addr:172.16.1.1  Bcast:172.16.1.255  Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:389016 errors:16534 dropped:0 overruns:0 rame:24522
      TX packets:400845 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:100
      Interrupt:11 Base address:0xcc00

You  may also use this command as :

ifconfig -a - view all the interfaces either active or inactive.
ifconfig eth0 down - shut down eth0
ifconfig eth1 up - activate eth1
ifconfig eth0 arp - enable ARP on eth0
ifconfig eth0 -arp - disable ARP on eth0
ifconfig eth0 netmask 255.255.255.0 - set the eth0 netmask
ifconfig lo mtu 2000 - set the loopback maximum transfer unit
ifconfig eth1 172.16.0.7 - set the eth1 IP address

 

route - adds predefined routes for interface devices to the Forwarding Information Base (FIB).

usage : route add -net ${NETWORK} netmask ${NMASK} dev ${DEVICE}

example : route add -net 192.168.1.0 netmask 255.255.255.0 dev eth1

usage : route add -host ${IPADDR} ${DEVICE}

example : route add -host 192.168.2.2 eth2

This displays the Kernel IP routing table by using "route -n" :

Kernel IP routing table
Destination   Gateway     Genmask         Flags Metric Ref Use Iface
172.16.1.4    *           255.255.255.255 UH    0      0     0 eth0
172.16.1.0    *           255.255.255.0   U     0      0     0 eth0
127.0.0.0     *           255.0.0.0       U     0      0     0 lo
default       172.16.1.1  0.0.0.0         UG    0      0     0 eth0

You may also use this command to change your default gateway :

usage : route add default gw ${IPADDR}

example : route add default gw 172.16.1.2

No comments: