Monday, July 30, 2012

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


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

Hey Folks , as we have already learnt the three most basic networking commands (Ifconfig, netstat and ping) in Linux in our last post we will now concentrate on the other most important networking commands in Linux.

1.traceroute :

Traceroute utilizes the IP protocol ‘time to live’ field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to some host. The only mandatory parameter is the destination host name or IP number. The default probe datagram length is 40 bytes, but this may be increased by specifying a packet length (in bytes) after the destination host name.So This command printa the route packets take to network host.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
Examples
traceroute computerandyou.net - would display results similar to the below example.
traceroute to computerandyou.net (166.70.11.24), 60 hops max, 80 byte packets
1 198.60.22.1 (198.60.22.1) 2.303 ms 1.424 ms 2.346 ms
2 krunk3.xmission.com (198.60.22.6) 0.742 ms * 1.521 ms

Note: in this example because we are local to the address we are tracerouting the amount of hops is very minimal. However, when you traceroute computerhope.com you may hop more than we do.

2.W-displays :

It provides the information about the users currently on the machine, and their processes. The header shows, in this order, the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes..
Syntax
w [-husfVo] [user] Examples
w
Would display information similar to the below example.
18:31:58 up 156 days, 5:16, 64 users, load average: 0.27, 0.27, 0.27
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

3.ARP :

Arp manipulates the kernel’s ARP cache in various ways. The primary options are clearing an address mapping entry and manually setting up one. For debugging purposes, the arp program also allows a complete dump of the ARP cache.ARP displays the IP address assigned to particular ETH card and mac address.
arp [-vn] [-H type] [-i if] -a [hostname] arp [-v] [-i if] -d hostname [pub] arp [-v] [-H type] [-i if] -s hostname hw_addr [temp] arp [-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub
arp [-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub
arp [-vnD] [-H type] [-i if] -f [filename]

4.mtr :

This is 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
To start mtr just type command (default is GUI interface):$ mtr upstream.router.isp.com
$ mtr sl-gw9-nyc-8-0.sprintlink.net
$ mtr -n router-ip
$ mtr gsrmum.vsnl.net.in

5.whois :

This command looks up a domain name in the internic whois database.
whois [ -h host ] identifier
-h host Host which holds the identification information.
identifier Name or host you wish to identify

6.finger :

This command displays the information on a system user.i.e. finger user@host Uses $HOME/.plan and $HOME/.project user files.
Finger example :
adeetkds@celltadm:/home/celltadm $ finger
Login Name TTY Idle When Where
celltadm Pakulla;Joachim;TIDI pts/1 1 Tue 09:09 145.16.229.12
celltadm Pakulla;Joachim;TIDI pts/2 Tue 09:13 145.16.229.12
celltadm Pakulla;Joachim;TIDI pts/3 1:01 Mon 07:56 145.16.229.12
celltadm Pakulla;Joachim;TIDI pts/4 19: Mon 13:44 adeebkbs.mdv.mmo.de
vdwrk510 Wienen;Alfons;+49211 pts/5 1:33 Tue 07:43 145.16.229.12
celltadm Pakulla;Joachim;TIDI pts/6 19: Mon 09:27 145.16.229.12
celltadm Pakulla;Joachim;TIDI pts/7 Tue 09:13 145.16.229.12
adeetkds@celltadm:/home/celltadm $

7.iptables:

It shows -IP firewall administration (Linux kernel 2.6/2.4).
iptables -L
cat /etc/sysconfig/iptables
View the current firewall configuration
View/read the real firewall file
Edit the iptables file:
pico /etc/sysconfig/iptables Edit and Save the firewall iptables file
.# This firewall is an example of a Linux web, ftp, pop3 & smtp server
.# It also limits ssh access to a block of IP - you need to customize the IPs to match your allowed IPs for ssh access
*filter
:INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [131962:7397220] :inputf - [0:0] -A INPUT -j inputf
-A FORWARD -j inputf
-A inputf -i lo -j ACCEPT
-A inputf -m state --state RELATED,ESTABLISHED -j ACCEPT
-A inputf -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A inputf -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A inputf -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A inputf -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A inputf -p tcp -m state --state NEW -m tcp --dport 110 -j ACCEPT
-A inputf -s 192.168.1.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
-A inputf -p ipv6-crypt -j ACCEPT
-A inputf -p ipv6-auth -j ACCEPT
-A inputf -j REJECT --reject-with icmp-host-prohibited
COMMIT
shutdown -r now Restart the server
If you know these commands in Linux you are going to have a good time networking ;) .

No comments:

Post a Comment