Monday, July 30, 2012

Beginners Guide to know the network in Linux command line [Part 1]


Beginners Guide to know the network in Linux command line [Part 1]

Linux is the most powerful operating system and we often need to use certain commands to explore its power effectively and efficiently. So Today we summarized the most interesting and useful networking commands which every Linux user are supposed to be familiar with it so that we can do our work faster.But Before we get to know the commands let’s have a look at some Important files in our OS.

Important files in Linux TCP/IP Network Configuration:

1./etc/resolve.conf : This file Lists the DNS servers for internet domain name resolution.
2./etc/hosts : This file lists the hosts to be resolved locally and not by the DNS.
3./etc/nsswitch.conf :This file lists the order of host name search. Typically look at local files, then NIS server, then DNS server.
4.Red Hat/Fedora/CentOS might have a /etc/sysconfig/network file to specify the network configuration.
5.Red Hat/Fedora/CentOS might also have a /etc/sysconfig/network-scripts/ifcfg-device file which specifies TCP network information.
6./network/interfaces/:And our favourite Ubuntu/Debian must have a etc/network/interfaces file to specify network configuration and devices.For EXample Static IP and DHCP etc.

Some Useful Linux Networking Commands:

1.Ifconfig : We type if config into the terminal to determine whether the network been detected or not.Ifconfig is used to configure the network interfaces.Normally we use this command to check the IP address assigned to the system.It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.
Example 1. Display Details of All interfaces Including Disabled Interfaces
# ifconfig -a
Example 2.Disable an Interface
# ifconfig MIG down
Example 3.Enable an Interface
# ifconfig MIG up
Example 4.Assign ip-address to an Interface
Assign 192.168.2.1 as the IP address for the interface MIG.
# ifconfig MIG 192.168.2.1

2.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
examples :
netstat -nap : List all connected processes.
netstat -s : Show network statistics.
netstat -rn : Display routing table info.
Example 1: List all ports using netstat -a
# netstat -a | more 
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30035         *:*                     LISTEN
udp        0      0 *:bootpc                *:*                                

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     6135     /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     5140     /var/run/acpid.socket
Example 2: List all tcp ports using netstat -at
# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
tcp        0      0 localhost:ipp           *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN
Example 3: List all udp ports using netstat -au
# netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 *:bootpc                *:*
udp        0      0 *:49115                 *:*
udp        0      0 *:mdns                  *:*
3.ping : This command sends the ICMP ECHO_REQUEST packets to the network hosts. We Use Cntl-C to stop the ping command. ping command is used to check the connectivity of a system to a network.Whenever there is a problem in network connectivity we use ping to ensure the system is connected to network.
Example:Test the connection to server yahoo.com server, enter:
ping yahoo.com
Sample outputs:
PING yahoo.com (209.191.93.53) 56(84) bytes of data.
64 bytes from b1.www.vip.mud.yahoo.com (209.191.93.53): icmp_seq=1 ttl=50 time=311 ms
64 bytes from b1.www.vip.mud.yahoo.com (209.191.93.53): icmp_seq=2 ttl=50 time=310 ms
64 bytes from b1.www.vip.mud.yahoo.com (209.191.93.53): icmp_seq=3 ttl=50 time=309 ms
64 bytes from b1.www.vip.mud.yahoo.com (209.191.93.53): icmp_seq=4 ttl=50 time=310 ms
^C
--- yahoo.com ping statistics ---
5 packets transmitted, 4 received, 20% packet loss, time 4007ms
rtt min/avg/max/mdev = 309.710/310.718/311.594/0.966 ms
Lets do networking at Linux with ease now.

No comments:

Post a Comment