jump to navigation

Linux network commands December 16, 2010

Posted by Tournas Dimitrios in Linux.
Tags:
trackback

Linux, which is based on Unix, is a network operating system. It is an operating system designed to serve end user systems such as workstation and personal computer.
Linux also provide other important network services including printer sharing, database sharing, ftp, NFS , webserver , FTP ,routing, firewall and so on.
In this article , user will learn from basic network configuration which is configuring network interface card to the advanced server configuration.
The command line utilities that will be covered are :

  • Linux ifconfig command
  • Linux netstat command
  • Basic ftp command
  • Linux route command
  • Linux ping command
  • Install and using Lynx web browser in CentOs

A newcomer to the world of Linux may be scared from the different jargons , but promise you  , with a little 🙂  exercise , these commands will become a second nature to you .

The ifconfig command : Ifconfig command is used to configure network interfaces. ifconfig stands for interface configurator. Ifconfig is widely used to initialize the network interface and to enable or disable the interfaces.

The ifconfig command
ifconfig eth0 Ifconfig, when invoked with no arguments will display all the details of currently active interfaces. If you give the interface name as an argument, the details of that specific interface will be displayed.
ifconfig  -a Display Details of All interfaces Including Disabled Interfaces
  • ifconfig eth0 down
  • ifconfig eth0 up
  • Disable an Interface
  • Enable an Interface
ifconfig eth0 192.168.2.2 Assign 192.168.2.2 as the IP address for the interface eth0.
ifconfig eth0 netmask 255.255.255.0 Change Subnet mask of the interface eth0.
ifconfig eth0 broadcast 192.168.2.255 Change Broadcast address of the interface eth0.
ifconfig eth0 mtu XX This will change the Maximum transmission unit (MTU) to XX. MTU is the maximum number of octets the interface is able to handle in one transaction. For Ethernet the Maximum transmission unit by default is 1500.

The netstat command : Linux netstat command is another useful network utility in Linux. We can use netstat to list network connections, view routing table and information about network interface. The netstat command has been one of useful tools for network troubleshooting. This tutorial is a basic guide to the netstat command with usage examples to help the new Linux beginner.

The netstat command
netstat  -[aisl] Lists all listening and non-listening sockets using netstat command with -a option:

Displays statistics for Linux network interfaces using netstat command with -i option:

Lists listening sockets using netstat command with -l option:

Displays summary information for each protocol using netstat command with -s option:

netstat  -r Displays Linux routing table using netstat command with -r option:
netstat -ap | grep ssh Find out on which port a program is running
netstat -ie Display extended information on the interfaces (similar to ifconfig) using netstat -ie:
netstat -c Print netstat information continuously
netstat -an When you don’t want the name of the host, port or user to be displayed, use netstat -n option. This will display in numbers, instead of resolving the host name, port name, user name.
netstat -[tu] Display only ports related to the udp / tcp protocol
netstat -pt netstat -p option can be combined with any other netstat option. This will add the “PID/Program Name” to the netstat output. This is very useful while debugging to identify which program is running on a particular port.
netstat -s[tu] Show the statistics for each protocol tcp and or udp

The route command : Besides Linux ifconfig command, the Linux route command is another important network commands every Linux user should know. The route command can be used to add or modify a static route and a default gateway in the Linux or Unix system. As specify in the Linux Programmer’s Manual, Linux route command shows or manipulate the IP routing table. The IP stated is the Internet Protocol (ip address, netmask, gateway) which has been set during configuring network interface card (NIC) in the Linux ifconfig table earlier.

The Linux route command comes with many options but most network administrators familiar with add and del options. The route add command is used to add a new route while the route del command is to delete a route.

The route command
route  add  -net  192.168.1.0  netmask  255.255.255.0  dev  eth0 To add a new ip route via eth0 (first Ethernet card), issue route add command in this format:
route  add  -net  192.168.1.0  gw  192.168.1.1
netmask  255.255.255.0  dev  eth0
You can also add a gateway:
route Show the routing table
route   -n Show the routing table in numeric format

EXAMPLES
route add -net 127.0.0.0
adds the normal loopback entry, using netmask 255.0.0.0 (class
A net, determined from the destination address) and  associated
with  the “lo” device (assuming this device was prviously set up
correctly with ifconfig(8)).

route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0
adds a route to the network 192.56.76.x via “eth0”. The Class  C
netmask modifier is not really necessary here because 192.* is a
Class C IP address. The word “dev” can be omitted here.

route add default gw mango-gw
adds a default route (which will    be  used  if  no  other route
matches).  All  packets using  this route will be gatewayed
through “mango-gw”. The device which will actually be used for
that route depends on how we can reach “mango-gw” – the static
route to “mango-gw” will have to be set up before.

route add ipx4 sl0
Adds the route to the “ipx4” host via the SLIP interface (assum-
ing that “ipx4” is the SLIP host).

route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4
This command adds the net “192.57.66.x” to be gatewayed
through the former route to the SLIP interface.

route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
This is an obscure one documented so people know how to do
it. This  sets  all  of  the class D (multicast) IP routes to go via
“eth0”. This is the correct normal  configuration line with a
multicasting kernel.

route add -net 10.0.0.0 netmask 255.0.0.0 reject
This   installs  a  rejecting  route  for     the  private  network
“10.x.x.x.”

OUTPUT
The output of the kernel routing table is organized in the following
columns

Destination
The destination network or destination host.

Gateway
The gateway address or ‘*’ if none set.

Genmask
The  netmask for the  destination net; ‘255.255.255.255’ for a
host destination and ‘0.0.0.0’ for the default route.

Flags  Possible flags include
U (route is up)
H (target is a host)
G (use gateway)
R (reinstate route for dynamic routing)
D (dynamically installed by daemon or redirect)
M (modified from routing daemon or redirect)
A (installed by addrconf)
C (cache entry)
!     (reject route)

Metric
The ‘distance’ to the target (usually counted in hops). It is
not  used     by  recent kernels, but may be needed by routing
daemons.

Ref    Number of references to this route. (Not used in the Linux  ker-
nel.)

Use    Count  of lookups for the route. Depending on the use of -F
and  -C this will be either route cache misses (-F) or hits (-C).

Iface  Interface to which packets for this route will be sent.

MSS    Default maximum segement size  for TCP connections over
this route.

Window Default window size for TCP connections over this route.

irtt   Initial  RTT  (Round Trip Time). The kernel uses this to guess
about the best TCP protocol parameters without waiting on (pos-
sibly slow) answers.

HH (cached only)
The  number  of  ARP entries and cached routes that refer to the
hardware header cache for the cached route. This will be -1 if a
hardware    address     is not needed for the interface of the cached
route (e.g. lo).

Arp (cached only)
Whether or not the hardware address for the cached route
is up to date.

EXAMPLES
       route add -net 127.0.0.0
	      adds the normal loopback entry, using netmask 255.0.0.0 (class
              A net, determined from the destination address) and  associated
	      with  the "lo" device (assuming this device was prviously set up
	      correctly with ifconfig(8)).

       route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0
	      adds a route to the network 192.56.76.x via "eth0". The Class  C
	      netmask modifier is not really necessary here because 192.* is a
	      Class C IP address. The word "dev" can be omitted here.

       route add default gw mango-gw
	      adds a default route (which will	be  used  if  no  other route
	      matches).  All  packets using  this route will be gatewayed
	      through "mango-gw". The device which will actually be used for
	      that route depends on how we can reach "mango-gw" - the static
	      route to "mango-gw" will have to be set up before.

       route add ipx4 sl0
	      Adds the route to the "ipx4" host via the SLIP interface (assum-
	      ing that "ipx4" is the SLIP host).

       route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4
	      This command adds the net "192.57.66.x" to be gatewayed
              through the former route to the SLIP interface.

       route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
	      This is an obscure one documented so people know how to do
              it. This  sets  all  of  the class D (multicast) IP routes to go via
	      "eth0". This is the correct normal  configuration line with a
	      multicasting kernel.

       route add -net 10.0.0.0 netmask 255.0.0.0 reject
	      This   installs  a  rejecting  route  for	 the  private  network
	      "10.x.x.x."

OUTPUT
       The output of the kernel routing table is organized in the following
       columns

       Destination
	      The destination network or destination host.

       Gateway
	      The gateway address or '*' if none set.

       Genmask
	      The  netmask for the  destination net; '255.255.255.255' for a
	      host destination and '0.0.0.0' for the default route.

       Flags  Possible flags include
	      U (route is up)
	      H (target is a host)
	      G (use gateway)
	      R (reinstate route for dynamic routing)
	      D (dynamically installed by daemon or redirect)
	      M (modified from routing daemon or redirect)
	      A (installed by addrconf)
	      C (cache entry)
	      !	 (reject route)

       Metric
              The 'distance' to the target (usually counted in hops). It is
	      not  used	 by  recent kernels, but may be needed by routing
              daemons.

       Ref    Number of references to this route. (Not used in the Linux  ker-
	      nel.)

       Use    Count  of lookups for the route. Depending on the use of -F
             and  -C this will be either route cache misses (-F) or hits (-C).

       Iface  Interface to which packets for this route will be sent.

       MSS    Default maximum segement size  for TCP connections over
              this route.

       Window Default window size for TCP connections over this route.

       irtt   Initial  RTT  (Round Trip Time). The kernel uses this to guess
	      about the best TCP protocol parameters without waiting on (pos-
	      sibly slow) answers.

       HH (cached only)
	      The  number  of  ARP entries and cached routes that refer to the
	      hardware header cache for the cached route. This will be -1 if a
	      hardware	address	 is not needed for the interface of the cached
	      route (e.g. lo).

       Arp (cached only)
	      Whether or not the hardware address for the cached route
              is up to date.

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s