Custom Search

LINUX

Usefull Linux networking commands:
  • /etc/rc.d/init.d/network   start - command to start, restart or stop the network
  • netstat - Display connections, routing tables, stats etc
    • List externally connected processes: netstat -punta
      • -a: Show both listening and non-listening sockets.
      • -p: Show PID of process owning socket
      • -u: Show UDP
      • -t: Show TCP
      • -n: Show IP addresses only. Don't resolve host names
      • -g: Show multi-cast group membership info
      • -c: Continuous mode - update info every second
      • -v: Verbose
      • -e: Extended information
      • -o: show network timer information
    • List all connected processes: netstat -nap
    • Show network statistics: netstat -s
    • Display routing table info: netstat -nr
      $ netstat -nr
      Kernel IP routing table
      Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
      192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
      169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
      0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0 
      Flags:
      • G: route uses gateway
      • U: Interface is "up"
      • H: Only a single host is accessible (eg. loopback)
      • D: Entry generated by ICMP redirect message
      • M: Modified by ICMP redirect message
    • Display interface statistics: netstat -i
      $ netstat -i
      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     2224      0      0      0     1969      0      0      0 BMRU
      lo        16436   0     1428      0      0      0     1428      0      0      0 LRU
      Where:
      • RX-OK/TX-OK: number of packets transmitted/received error free
      • RX-ERR/TX-ERR: number of dammaged/error packets transmitted/received
      • RX-DRP/TX-DRP: number of dropped packets
      • RX-OVR/TX-OVR: number of packets dropped because of a buffer overrun
      Flags:
      • B: A broadcast address has been set
      • L: This interface is a loopback device
      • M: All packets are received (promiscuous mode)
      • N: Trailers are avoided
      • O: ARP is turned off for this interface
      • P: Point-to-point connection
      • R: Interface is running
      • U: Interface is up
  • ping - send ICMP ECHO_REQUEST packets to network hosts. Use Cntl-C to stop ping.
  • traceroute - print the route packets take to network host.
    (Ubuntu Note: Typically Ubuntu installs tracepath for IPv4 and traceroute6 for IPv6. One can install traceroute: apt-get install traceroute)
    • traceroute IP-address-of-server
    • traceroute domain-name-of-server
  • mtr - a network diagnostic tool introduced in Fedora - Like traceroute except it gives more network quality and network diagnostic info. Leave running to get real time stats. Reports best and worst round trip times in milliseconds.
    • mtr IP-address-of-server
    • mtr domain-name-of-server
  • whois - Lookup a domain name in the internic whois database.
  • finger - Display information on a system user. i.e. finger user@host Uses $HOME/.plan and $HOME/.project user files. Often used by game developers.
  • socklist - Display list of open sockets, type, port, process id and the name of the process. Kill with fuser or kill.
  • host - Give a host name and the command will return IP address. Unlike nslookup, the host command will use both /etc/hosts as well as DNS.
    Example: host domain-name-of-server
  • nslookup - Give a host name and the command will return IP address.  Note that nslookup does not use the /etc/hosts file.
  • *************************************************
Assigning an IP address:
Computers may be assiged a static IP address or assigned one dynamically. Typically a server will require a static IP while a workstation will use DHCP (dynamic IP assignment). The Linux server requires a static IP so that those who wish to use its resources can find the system. It is more easily found if the IP address does not change and is static. This is not important for the Linux client workstation and thus it is easier to use an automated Dynamic Host Configuration Protocol (DHCP) for IP address assignment.

Static IP address assignment:

Command Line:
    /sbin/ifconfig eth0 192.168.10.12 netmask 255.255.255.0 broadcast 192.168.10.255
    Network address by convention would be the lowest: 192.168.10.0    
Broadcast address by convention would be the highest: 192.168.10.255
The gateway can be anything, but following convention: 192.168.10.1
Note: the highest and lowest addresses are based on the netmask. The previous example is based on a netmask of 255.255.255.0