Introduction to Networking Tools for Gnubies
By Joshua Birnbaum <Pg.2>

1. Summary: Show characteristics of all network interfaces present on the system.
   Command: netstat -ina [-i: show interfaces, -n: don't use DNS, -a: show downed interfaces]

   mir 1% netstat -ain
   Kernel Interface table
   Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR   TX-OK TX-ERR TX-DRP TX-OVR Flg
   eth0   1500   0 1561687      0      0      0 1332073      1      0      0 BMRU
   eth1   1500   0       0      0      0      0       0      0      0      0 BM
   lo    16436   0     419      0      0      0     419      0      0      0 LRU

2. Summary: Identify the program (PID) that opened a given port.
   1st Command: netstat -ln [-l: show listening sockets, -n: don't use DNS]
   2nd Command: netstat -lpn [-p: show PID that opened port [NOTE: requires root]]
   3rd Command: ps -e | grep <PID> [-e: selects all processes]

   mir 1# netstat -ln
   Active Internet connections (only servers)
   Proto Recv-Q Send-Q Local Address           Foreign Address         State

   tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN <ssh>
   tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN <???>
   mir 2# netstat -lnp

   Active Internet connections (only servers)
   Proto Recv-Q Send-Q Local Address           Foreign Address         State     PID/Program name
   tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN    179/sshd
   tcp        0      0 0.0.0.0:111            
0.0.0.0:*               LISTEN    90/portmap
   mir 3# ps -e | grep 90
      PID TTY          TIME CMD
      90 ?         00:00:00 portmap

   << result: port 111/tcp is the portmap daemon - fine as system mir is an NFS server >>

3. Summary: Take an inventory of all IP addresses in use on the network.
   1st Command: ping
<NETWORK_BROADCAST_ADDRESS>
   2nd Command: arp -a [-a: displays contents of arp cache]

   mir 1% ping 192.168.1.255
   mir 2% arp -a
   saturn.rockets.com (192.168.1.4) at 08:00:20:75:C7:0C [ether] on eth0
   atlas.rockets.com (192.168.1.2) at 08:00:69:0A:4C:42 [ether] on eth0
   titan.rockets.com (192.168.1.3) at 08:00:20:81:07:33 [ether] on eth0

4. Summary: Change an IP address on a network interface.
   1st Command: ifconfig <INTERFACE> down               [NOTE: requires root]
   2nd Command: ifconfig 
<INTERFACE> <NEW_IP_ADDRESS>   [NOTE: requires root]
   3rd Command:
ifconfig <INTERFACE>

   mir 1# ifconfig eth0 down
   mir 2# ifconfig eth0 192.168.1.10
   mir 3# ifconfig eth0                                 [NOTE: always check your work]
   eth0      Link encap:Ethernet  HWaddr 08:00:20:20:11:76
             inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
             UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
             RX packets:1564440 errors:0 dropped:0 overruns:0 frame:0
             TX packets:1333782 errors:1 dropped:0 overruns:0 carrier:1
             collisions:14669 txqueuelen:1000
             RX bytes:735535580 (701.4 MiB)  TX bytes:363638832 (346.7 MiB)
             Interrupt:38

5. Summary: Check if any interfaces are in promiscuous mode - if so, shut them down.
   Command: ifchk -d [-d: shut down promiscuous interfaces [NOTE: requires root]]

   mir 2# ifchk -d
   interface(s): 3
       lo: normal
     eth0: PROMISC [*] <--- promisc interface eth0 was shut down
     eth1: *down*

6. Summary: Configure a default route for the system.
   1st Command:
route add default gw <IP_ADDRESS_OF_DEFAULT_GATEWAY> [NOTE: requires root]
   2nd Command: netstat -r [-r: display the system routing table]

   mir 1# route add default gw 192.168.1.1
   mir 2# netstat -r                                    [NOTE: always check your work]
   Kernel IP routing table
   Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
   192.168.1.0     *               255.255.255.0   U        40 0          0 eth0
   127.0.0.0       *               255.0.0.0       U        40 0          0 lo
   default         192.168.1.1     0.0.0.0         UG       40 0          0 eth0

<< PG.1 << | About | Contact | FAQ | Publications | Resume | Software | Speaking | Noorg

Copyright © 1998-2008 Noorg, Inc.
All Rights Reserved.