Networking Commanads 2
Networking Commanads 2
ping
The ping command (named after the sound of an active sonar system) sends echo requests to the host
specified on the command line, and lists the responses received.
$ ping ipAddress or hostname
e.g
$ ping www.vit.ac.in
• ping - sends an ICMP ECHO_REQUEST packet to the specified host. If the host responds, an
ICMP packet is received.
• One can “ping” an IP address to see if a machine is alive.
• It provides a very quick way to see if a machine is up and connected to the network.
netstat
• It works with the LINUX Network Subsystem, it will tell you what the status of ports are ie. open,
closed, waiting connections. It is used to display the TCP/IP network protocol statistics and
information.
tcpdump
This is a sniffer, a program that captures packets off a network interface and interprets them.
hostname
Tells the user the host name of the computer they are logged into.
traceroute
traceroute will show the route of a packet. It attempts to list the series of hosts through which your
packets travel on their way to a given destination.
Command syntax:
traceroute machine_name_or_ip
e.g traceroute www.vit.ac.in
Each host will be displayed, along with the response times at each host.
finger
Retrieves information about the specified user.
e.g finger bit50001
ifconfig ( In Windows use ipconfig )
This command is used to configure network interfaces, or to display their current configuration.
dig
The "domain information groper" tool. If you give a hostname as an argument to output information
about that host, including it's IP address, hostname and various other information.
e.g dig vitlinux
telnet
telnet allows you to log in to a computer, just as if you were sitting at the terminal. Once your
username and password are verified, you are given a shell prompt. From here, you can do anything
requiring a text console.
ftp
To connect to an FTP server use
ftp ipaddress
netstat
Displays contents of /proc/net files. It works with the LINUX Network Subsystem, it will tell
you what the status of ports are ie. open, closed, waiting, masquerade connections. It will also
display various other things. It has many different options.
tcpdump
This is a sniffer, a program that captures packets off a network interface and interprets them
for you. It understands all basic internet protocols, and can be used to save entire packets for
later inspection.
ping
The ping command (named after the sound of an active sonar system) sends echo requests to
the host you specify on the command line, and lists the responses received their round trip
time.
ping ip_or_host_name
hostname
Tells the user the host name of the computer they are logged into. Note: may be called host.
traceroute
traceroute will show the route of a packet. It attempts to list the series of hosts through which
your packets travel on their way to a given destination. Also have a look at xtraceroute (one
of several graphical equivalents of this program).
Command syntax:
traceroute machine_name_or_ip
tracepath
tracepath performs a very simlar function to traceroute the main difference is that tracepath
doesn't take complicated options.
Command syntax:
tracepath machine_name_or_ip
findsmb
findsmb is used to list info about machines that respond to SMB name queries (for example
windows based machines sharing their hard disk's).
Command syntax:
Findsmb
This would find all machines possible, you may need to specify a particular subnet to query
those machines only...
nmap
“ network exploration tool and security scanner”. nmap is a very advanced network tool used
to query machines (local or remote) as to whether they are up and what ports are open on
these machines.
A simple usage example:
nmap machine_name
This would query your own machine as to what ports it keeps open. nmap is a very powerful
tool, documentation is available on the nmap site as well as the information in the manual
page.
telnet
Someone once stated that telnet(1) was the coolest thing he had ever seen on computers. The ability
to remotely log in and do stuff on another computer is what separates Unix and Unix-like operating
systems from other operating systems.
telnet allows you to log in to a computer, just as if you were sitting at the terminal. Once your
username and password are verified, you are given a shell prompt. From here, you can do anything
requiring a text console. Compose email, read newsgroups, move files around, and so on. If you are
running X and you telnet to another machine, you can run X programs on the remote computer and
display them on yours.
% telnet <hostname>
If the host responds, you will receive a login prompt. Give it your username and password. That's it.
You are now at a shell. To quit your telnet session, use either the exit command or the logout
command.
telnet does not encrypt the information it sends. Everything is sent in plain text, even passwords.
It is not advisable to use telnet over the Internet. Instead, consider the Secure Shell. It encrypts
all traffic and is available for free.
Now that we have convinced you not to use the telnet protocol anymore to log into a remote machine,
we'll show you a couple of useful ways to use telnet.
You can also use the telnet command to connect to a host on a certain port.
% telnet <hostname> [port]
This can be quite handy when you quickly need to test a certain service, and you need full control
over the commands, and you need to see what exactly is going on. You can interactively test or use
an SMTP server, a POP3 server, an HTTP server, etc. this way.
In the next figure you'll see how you can telnet to a HTTP server on port 80, and get some basic
information from it.
% telnet store.slackware.com 80
Trying 69.50.233.153...
Connected to store.slackware.com.
HEAD / HTTP/1.0
HTTP/1.1 200 OK
ETag: "193424-c0-3e9fda6e"
Accept-Ranges: bytes
Content-Length: 192
Connection: close
Content-Type: text/html
Connection closed by foreign host.
1-)arp :
When we need an Ethernet (MAC) address we can use arp(address resolution protocol).
Example:
2-)nslookup:
Example:
Server: ns3.inet.tele.dk
Address: 193.162.153.164
Non-authoritative answer:
Name: itu.dk
Address: 130.226.133.2
NOTE :If you write the command as above it shows as default your pc's server name firstly.
Server: superman.itu.dk
Address: 130.226.133.2
Non-authoritative answer:
Name: login.yahoo.akadns.net
Address: 216.109.127.60
NOTE:Remark that in the second example we do not see the default server name.
There are many nslookup with optional commands.To read them type nslookup and enter
3-)finger:
Example:
NOTE :I could not find out the name of the server that we log on (windows) at the school.
NOTE :What I did is :I first check the online users,and get a list of them(above).
Plan:
[hilmiolgun@ssh hilmiolgun]$
4-)ping:
Example:
5-)tracert:
Example:
2 29 ms 19 ms 29 ms ge-0-2-1-2.1000M.albnxu1.ip.tele.dk [195.249.1.2 9]
3 29 ms 29 ms 19 ms pos1-0.622M.lynxg1.ip.tele.dk [195.249.2.46]
5 29 ms 29 ms 19 ms 130.225.244.214
6 29 ms 29 ms 29 ms 1.ku.forskningsnettet.dk [130.225.245.90]
7 29 ms 29 ms 29 ms rk.itu.forskningsnettet.dk [130.226.249.30]
8 29 ms 29 ms 29 ms 130.225.245.86
9 29 ms 29 ms 29 ms tarzan.itu.dk [130.226.133.3]
Trace complete.
6-)ftp:
Example:Lets you dont have an ftp software and you want to get a file from your school harddisk.
So to do that:
ftp> open
To ftp.itu.dk
Connected to ssh.itu.dk.
ftp,open,ftp.itu.dk
Password:
ftp> help
NOTE: If it is your first time to those commands just type help and get the commands.If you dont
know how to use
ftp> dir
150 Opening ASCII mode data connection for testing.txt (148 bytes)
NOTE :After taking a look to the school harddisk ,I copied a file "testing.txt" to my local harddisk....
ftp> !dir
ftp> dir
ftp>
NOTE:At the end first looking at the local working directory and sending a file "love.wav" to the
school harddisk.
7-)net:
Example:
NET COMMANDS
NET PRINT
\\computername\sharename
For each queue, the display lists jobs, showing the size
Finally in addition to above there are also those commands: hostname ,lpq, lpr ,rsh ,tftp ,nbstat
,netstat.
To get familiar with those commands simply type commandname /? at the command line.
C:\>net
C:\>net use
New connections will not be remembered.
-------------------------------------------------------------------------------
C:\>net user
-------------------------------------------------------------------------------
Administrator Guest
C:\>net statistics
Server
Workstation
-s option.
are shown for TCP, UDP and IP; the -p option may be used
C:\>net name
Name
-------------------------------------------------------------------------------
CSE-DEPT-05
C:\>net session
-------------------------------------------------------------------------------
C:\>net localgroup
-------------------------------------------------------------------------------
Server Comment
ba8b326b)
Server hidden No
C:\>net share
abishek E:\abishek
akshu E:\akshu
ifconfig
This will simply list all information on all network devices currently up.
This will take eth0 (assuming the device exists) down, it won't be able to receive or send
anything until you put the device back “up” again.
Clearly there are a lot more options for this tool, you will need to read the manual/info page to
learn more about them.
ifup
Use ifup device-name to bring an interface up by following a script (which will contain your
default networking settings). Simply type ifup and you will get help on using the script.
ifup eth0
ifdown
Use ifdown device-name to bring an interface down using a script (which will contain your
default network settings). Simply type ifdown and you will get help on using the script.
ifdown eth0
ifcfg
Use ifcfg to configure a particular interface. Simply type ifcfg to get help on using this script.
For example, to change eth0 from 192.168.0.1 to 192.168.0.2 you could do:
The first command takes eth0 down and removes that stored IP address and the second one
brings it back up with the new address.
route
The route command is the tool used to display or modify the routing table. To add a gateway
as the default you would type:
host
Performs a simple lookup of an internet address (using the Domain Name System, DNS).
Simply type:
host ip_address
or
host domain_name
dig
The "domain information groper" tool. More advanced then host... If you give a hostname as
an argument to output information about that host, including it's IP address, hostname and
various other information.
dig www.amazon.com
To find the host name for a given IP address (ie a reverse lookup), use dig with the `-x' option.
dig -x 100.42.30.95
This will look up the address (which may or may not exist) and returns the address of the
host, for example if that was the address of “http://slashdot.org” then it would return
“http://slashdot.org”.
dig takes a huge number of options (at the point of being too many), refer to the manual page
for more information.
whois
(now BW whois) is used to look up the contact information from the “whois” databases, the
servers are only likely to hold major sites. Note that contact information is likely to be hidden
or restricted as it is often abused by crackers and others looking for a way to cause malicious
damage to organisation's.
wget
(GNU Web get) used to download files from the World Wide Web.
Use the -nc (no clobber) option to stop wget from overwriting a file if you already have it.
Use the -c or --continue option to continue a file that was unfinished by wget or another
program.
wget url_for_file
wget can also retrieve multiple files using standard wildcards, the same as the type used in
bash, like *, [ ], ?. Simply use wget as per normal but use single quotation marks (' ') on the
URL to prevent bash from expanding the wildcards. There are complications if you are
retrieving from a http site (see below...).
Advanced usage example, (used from wget manual page):
This will parse the file bookmarks.html and check that all the links exist.
Advanced usage: this is how you can download multiple files using http (using a wildcard...).
Notes: http doesn't support downloading using standard wildcards, ftp does so you may use
wildcards with ftp and it will work fine. A work-around for this http limitation is shown
below:
This will download (recursively), to a depth of one, in other words in the current directory and
not below that. This command will ignore references to the parent directory, and downloads
anything that ends in “.gif”. If you wanted to download say, anything that ends with “.pdf” as
well than add a -A.pdf before the website address. Simply change the website address and the
type of file being downloaded to download something else. Note that doing -A.gif is the same
as doing -A “*.gif” (double quotes only, single quotes will not work).
wget has many more options refer to the examples section of the manual page, this tool is very
well documented.
Alternative website downloaders: You may like to try alternatives like httrack. A full GUI
website downloader written in python and available for GNU/Linux
curl
curl is another remote downloader. This remote downloader is designed to work without user
interaction and supports a variety of protocols, can upload/download and has a large number
of tricks/work-arounds for various things. It can access dictionary servers (dict), ldap servers,
ftp, http, gopher, see the manual page for full details.
To access the full manual (which is huge) for this command type:
curl -M
For general usage you can use it like wget. You can also login using a user name by using the
-u option and typing your username and password like this:
netstat -a | grep LISTEN Show information about all open network ports
Set/view routing information
The command route can also be used to add or delete routes. Examples:
-p proto Shows connections for the protocol specified by proto; proto may be TCP or UDP.
If used with the -s option to display per-protocol statistics, proto may be TCP, UDP,
or IP.
-s Displays per-protocol statistics. By default, statistics are shown for TCP, UDP and IP;
the -p option may be used to specify a subset of the default.
interval Redisplays selected statistics, pausing interval seconds between each display. Press
CTRL+C to stop redisplaying statistics. If omitted, netstat will print the current
configuration information once.
C:\WINDOWS>netstat -a
Active Connections
Proto Local Address Foreign Address State
TCP My_Comp:ftp localhost:0 LISTENING
TCP My_Comp:80 localhost:0 LISTENING
C:\WINDOWS>netstat -an
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:21 0.0.0.0:0 LISTENING
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
By simply opening a browser connection to both the HTTP (port 80) and FTP (port 21) servers
(while still offline!), I saw the following:
C:\WINDOWS>netstat -a
Active Connections
Proto Local Address Foreign Address State
TCP My_Comp:ftp localhost:0 LISTENING
TCP My_Comp:80 localhost:0 LISTENING
TCP My_Comp:1104 localhost:0 LISTENING
TCP My_Comp:ftp localhost:1104 ESTABLISHED
TCP My_Comp:1102 localhost:0 LISTENING
TCP My_Comp:1103 localhost:0 LISTENING
TCP My_Comp:80 localhost:1111 TIME_WAIT
TCP My_Comp:1104 localhost:ftp ESTABLISHED
TCP My_Comp:1107 localhost:0 LISTENING
TCP My_Comp:1112 localhost:80 TIME_WAIT
UDP My_Comp:1102 *:*
UDP My_Comp:1103 *:*
UDP My_Comp:1107 *:*
This may be a bit confusing to some people, but remember I'm running BOTH the servers and clients
on the same machine in these examples. A little later (using both 'a' and 'n') I got this:
C:\WINDOWS>netstat -an
Active Connections
C:\WINDOWS>netstat -an
Active Connections
PING.exe
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
[-r count] [-s count] [[-j host-list] | [-k host-list]]
[-w timeout] destination-list
Options:
-t Ping the specifed host until interrupted.
-a Resolve addresses to hostnames.
-n count Number of echo requests to send.
-l size Send buffer size.
-f Set "Don't Fragment" flag in packet.
-i TTL Time To Live.
-v TOS Type Of Service.
-r count Record route for count hops.
-s count Timestamp for count hops.
-j host-list Loose source route along host-list.
-k host-list Strict source route along host-list.
-w timeout Timeout in milliseconds to wait for each reply.
It's also called the loopback address because you can ping it and get returns even when you're
offline (not connected to any network). If you don't get any valid replies, then there's a problem with
the computer's Network settings. Here's a typical response to the 'ping' command:
Here's another recent example using the name of my computer which I have tied to the IP number
127.0.0.1 in my C:\WINDOWS\HOSTS file:
C:\WINDOWS>ping My_Comp
Options:
-d Do not resolve addresses to hostnames.
-h maximum_hops Maximum number of hops to search for target.
-j host-list Loose source route along host-list.
-w timeout Wait timeout milliseconds for each reply.
Here's an example which traces the route from some ISP in Los Angeles to the main server at UCLA
in California ( note how two computers relatively close to each other may be routed way round
about! ):
C:\WINDOWS>tracert www.ucla.edu
NBTSTAT.exe
NBTSTAT [-a RemoteName] [-A IP address] [-c] [-n] [-r] [-R] [-s] [S] [interval]
-a (adapter status) Lists the remote machine's name table given its name.
-A (Adapter status) Lists the remote machine's name table given its IP address.
-s (sessions) Lists sessions table converting destination IP addresses to host names via the
hosts file.
interval Redisplays selected statistics, pausing interval seconds between each display. Press
Ctrl+C to stop redisplaying statistics.
ROUTE.exe
-f Clears the routing tables of all gateway entries. If this is used in conjunction
with one of the commands, the tables are cleared prior to running the command.
command Specifies one of four commands
PRINT Prints a route
ADD Adds a route
DELETE Deletes a route
CHANGE Modifies an existing route
MASK If the MASK keyword is present, the next parameter is interpreted as the
netmask parameter.
netmask If provided, specifies a sub-net mask value to be associated with this route entry.
If not specified, if defaults to 255.255.255.255.
-a Displays current ARP entries by interrogating the current protocol data. If inet_addr
is specified, the IP and Physical addresses for only the specified computer are
displayed. If more than one network interface uses ARP, entries for each ARP
table are displayed.
-g (Same as -a)
-N if_addr Displays the ARP entries for the network interface specified by if_addr.
-s Adds the host and associates the Internet address inet_addr with the Physical address
eth_addr. The Physical address is given as 6 hexadecimal bytes separated by hyphens.
The entry is permanent.