bash commands tutorial

Learning some advance bash commands(Related to network) in bash isn’t a bad idea if you are going to troubleshoot networking problems or you are interested in other network hacks.Although you can do it in ubuntu 10.04(In some older versions too) by using a special tool named Network Tools which allows you to execute these commands in graphical mode.It can be found at system -> administrator -> Network Tools.But if you know some basic commands related to networking then it will be better.It is very simple and you can learn it within minutes.Here is the simple bash commands tutorial part 4…(If you don’t know about some simple bash commands then first read here..Bash commands for beginners )

Ping Command :

It is one of the most used commands in network testing and management.You need to know either ip address or host name of the target.The result of the ping command can be use to decide whether the target host is alive or not.The syntax of the command is ping, followed by its address(host name or IP address).
ping zzz.zzz.zzz.zzz  or ping
user@user-desktop:~$ ping
PING (hhh.hhh.hhh.hhh) 56(84) bytes of data.
64 bytes fr0m (hhh.hhh.hhh.hhh): icmp_seq=1 ttl=49 time=287 ms
64 bytes fr0m (hhh.hhh.hhh.hhh): icmp_seq=2 ttl=49 time=269 ms
64 bytes fr0m (hhh.hhh.hhh.hhh): icmp_seq=3 ttl=49 time=272 ms
64 bytes fr0m hhh.hhh.hhh.hhh: icmp_seq=4 ttl=49 time=270 ms
64 bytes fr0m (hhh.hhh.hhh.hhh): icmp_seq=5 ttl=49 time=287 ms
64 bytes fr0m (hhh.hhh.hhh.hhh): icmp_seq=6 ttl=49 time=269 ms
64 bytes fr0m (hhh.hhh.hhh.hhh): icmp_seq=7 ttl=49 time=269 ms
64 bytes fr0m (hhh.hhh.hhh.hhh): icmp_seq=8 ttl=49 time=271 ms

Netstat Command :

Netstat is very useful in printing  the network connections,routing tables,network interfaces and multicast memberships.It has many advanced features that can be easily used by providing some options.Without any options it will display the list of open sockets.You can change the output by supplying options.

user@user-desktop:~$ netstat
unix  3      [ ]         STREAM     CONNECTED     9375     /home/user/.pulse/4f3877f89c59bcc05dbe2e5b4bb73a69-runtime/native
unix  3      [ ]         STREAM     CONNECTED     9374
unix  3      [ ]         STREAM     CONNECTED     9366     @/tmp/dbus-9GBsy9S5kY
unix  3      [ ]         STREAM     CONNECTED     9365
unix  3      [ ]         STREAM     CONNECTED     9322     /tmp/orbit-user/linc-5bc-0-6d4236a1652a7
unix  3      [ ]         STREAM     CONNECTED     9321
unix  3      [ ]         STREAM     CONNECTED     9320     /tmp/orbit-user/linc-602-0-19533f015c325
unix  3      [ ]         STREAM     CONNECTED     9316
unix  3      [ ]         STREAM     CONNECTED     9319     /tmp/orbit-user/linc-5fe-0-228e9d0f69c08

To display about kernel routing tables put -r , to know about the interfaces use -i and if you want the detailed statistics of each protocol then it is preferable to use -s.
e.g :
For Information about Interface :Using -i
user@user-desktop:~$ netstat -i
Kernel Interface table
eth0       1500 0    671613      0      0 0        671024      0      0      0 BMRU
lo        16436 0    103806      0      0 0        103806      0      0      0 LRU

For routing tables :
user@user-desktop:~$ netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface     *        U         0 0          0 eth0
link-local      *          U         0 0          0 eth0
default         UG        0 0          0 eth0

Detailed statistics of protocol using -s
user@user-desktop:~$ netstat -s
723094 total packets received
2 with invalid addresses
0 forwarded
0 incoming packets discarded
723053 incoming packets delivered
723066 requests sent out
367 ICMP messages received
2 input ICMP message failed.
ICMP input histogram:
destination unreachable: 353
source quenches: 14
69 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 69
InType3: 353
InType4: 14
OutType3: 69
18586 active connections openings
6738 passive connection openings
3445 failed connection attempts
1310 connection resets received
13 connections established
711836 segments received
696851 segments send out
14235 segments retransmited
18 bad segments received.
7544 resets sent
17343 packets received
69 packets to unknown port received.
0 packet receive errors
18471 packets sent

Options :
[-v] : To display some information about unconfigured address families.

[-n] : It will show the numerical address.

[-p] : To show the PID and name of the program to which each socket belongs.

[-l] : It will display only listening sockets.

[-c] : This will result in displaying the particular(selected) information every second continuously.

[-C] : Use to printing routing information fr0m its route cache.

Traceroute :

It is one of the most widely used commands,helpfull in tracing the route fr0m the a sender to a destination host.Actually it works by using TTL field of the IP protocol.For performing a trace the only required parameter is IP address or host name.There are many options available , some are desribed below.

Options :

[-I] : It uses ICMP(Internet control message access protocol) echos for probing.

[-T] : It uses TCP(Transmission control protocol) SYN for probes(Requires root power,so if you are not in root mode then start the command with sudo).

[-d] : It will enable the socket level debugging(If it is supported by your linux kernel).

[-F] : To prevent the fragmentation of the probe packets.

For Example : Tracing without any options
user@user-desktop:~$ traceroute
traceroute to (hhh.hhh.hhh.hhh), 30 hops max, 60 byte packets
1 (  1.204 ms  1.718 ms  2.220 ms
2 (FFF.FFF.FFF.FFF)  19.496 ms  22.417 ms  25.827 ms
3 (FFF.FFF.FFF.FFF)  21.537 ms  21.979 ms *
4  BBB.BBB.BBB.BBB (WWW.WWW.WWW.WWW)  29.870 ms  30.267 ms  33.412 ms
5 (MMM.MMM.MMM.MMM)  260.056 ms  263.774 ms  266.282 ms
6 (KKK.KKK.KKK.KKK)  265.844 ms  237.168 ms  424.466 ms
7  QQQ.QQQ.QQQ.QQQ (TTT.TTT.TTT.TTT)  267.514 ms  267.996 ms  268.273 ms
8 (  274.020 ms  278.394 ms  280.310 ms
9  YYY.YYY.YYY.YYY (PPP.PPP.PPP.PPP)  281.858 ms  284.450 ms  285.917 ms
10  SSS.SSS.SSS.SSS (SSS.SSS.SSS.SSS)  290.453 ms  291.939 ms  298.095 ms
11 (hhh.hhh.hhh.hhh)  301.548 ms  303.444 ms  303.724 ms

For more details on traceroute type : info traceroute in your bash shell.Actually you can learn bash commands fr0m the bash shell.Just type help command name or info command name or –help command name.

Leave a comment

Your email address will not be published. Required fields are marked *