Académique Documents
Professionnel Documents
Culture Documents
This tutorial explains Linux ping command, options and its usage with examples.
ping send ICMP ECHO_REQUEST to network hosts
DESCRIPTION
PING (Packet INternet Groper) command is the best way to test connectivity between
two nodes. Whether it is Local Area Network (LAN) or Wide Area Network (WAN). Ping
use ICMP (Internet Control Message Protocol) to communicate to other devices. You
can ping host name of ip address using below command.
ping uses the ICMP protocols mandatory ECHO_REQUEST datagram to elicit an ICMP
ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams (pings)
have an IP and ICMP header, followed by a struct timeval and then an arbitrary number
of pad bytes used to fill out the packet.
SYNOPSIS
ping -s [-d] [-l] [-L] [-n] [-r] [-R] [-v] [ -i interface_address ] [-I interval] [-t ttl] host
[packetsize] [count]
OPTIONS :
-d
Set
the
SO_DEBUG
socket
option.
-l
Loose source route. Use this option in the IP header to send the packet to the given host
and
back
again.
Usually
specified
with
the
-R
option.
-L
Turn off loopback of multicast packets. Normally, if there are members in the host group
on the out- going interface, a copy of the multicast packets will be delivered to the local
machine.
-n
Show network addresses as numbers. ping normally displays addresses as host names.
-r
Bypass the normal routing tables and send directly to a host on an attached network. If
the host is not on a directly-attached network, an error is returned. This option can be
used to ping a local host through an interface that has been dropped by the router
daemon.
-R
Record route. Sets the IP record route option, which will store the route of the packet
inside the IP header. The contents of the record route will only be printed if the -v option
is given, and only be set on return packets if the target host preserves the record route
option
across
echos,
or
the
-l
option
is
given.
-v
Verbose output. List any ICMP packets, other than ECHO_RESPONSE, that are
received.
-i interface_address
Specify the outgoing interface address to use for multicast packets. The default interface
address for multicast packets is determined from the (unicast) routing tables.
-I
interval
Specify the interval between successive transmissions. The default is one second.
-t
ttl
Specify the IP time to live for unicast and multicast packets. The default time to live for
unicast packets is set with ndd (using the icmp_def_ttl variable). The default time to live
for
multicast
is
one
hop.
host
The
network
host.
packetsize
Specified
size
of
packetsize.
Default
is
count
Amount of times to send the ping request.
EXAMPLES
1. Ping the host to see if its alive
$ ping google.com
PING google.com (74.125.200.102) 56(84) bytes of data.
64 bytes from plus.google.com (74.125.200.102): icmp_req=1 ttl=128 time=172 ms
64 bytes from plus.google.com (74.125.200.102): icmp_req=2 ttl=128 time=164 ms
64 bytes from plus.google.com (74.125.200.102): icmp_req=4 ttl=128 time=165 ms
^C
--- google.com ping statistics --4 packets transmitted, 3 received, 25% packet loss, time 3013ms
rtt min/avg/max/mdev = 164.618/167.289/172.010/3.364 ms
64.
Increase
Ping
Time
Example: Wait for 5 seconds before sending the next packet.
Interval
$ ping -i 5 google.com
Decrease
Ping
Time
Example: Wait 0.1 seconds before sending the next packet.
Interval
Note: Only super user can specify interval less than 0.2 seconds. If not, youll
get the following error message.
3. Send N packets and stop
$ ping -c 4 google.com
PING google.com (74.125.135.100) 56(84) bytes of data.
64 bytes from plus.google.com (74.125.135.100): icmp_req=1
64 bytes from plus.google.com (74.125.135.100): icmp_req=2
64 bytes from plus.google.com (74.125.135.100): icmp_req=3
64 bytes from plus.google.com (74.125.135.100): icmp_req=4
ttl=128
ttl=128
ttl=128
ttl=128
time=251
time=180
time=179
time=179
ms
ms
ms
ms
--- google.com ping statistics --4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 179.569/197.734/251.433/31.005 ms
Note : Ping Bytes Sent = Ping Packet Size + Ping Header Packet Size (28
bytes)
7. Timeout
The following example will ping for 5 seconds. i.e ping command will exit after
5 seconds irrespective of how many packets are sent or received.
$ ping -w 5 localhost
Note: If one of the hop in the path is not reachable then you will have failure in
pinging.
9. Record and print route of how ECHO_REQUEST sent and ECHO_REPLY
received
$ ping -R 192.168.1.63
PING 192.168.1.63 (192.168.1.63) 56(84) bytes of data.
64 bytes from 192.168.1.63: icmp_seq=1 ttl=61 time=2.05 ms
RR: 192.168.9.118
192.168.3.25
192.168.10.35
192.168.1.26
192.168.1.63
192.168.1.63
192.168.10.4
192.168.3.10
192.168.4.25
64 bytes from 192.168.1.63: icmp_seq=2 ttl=61 time=2.00 ms
(same route)
Note: It can give beep only from terminal number 1 through 7 and gnometerminal ( It will not work in console ).
DESCRIPTION
Ifconfig is used to configure the kernel-resident network interfaces. 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. If no arguments are given, ifconfig
displays the status of the currently active interfaces.
If a single interface argument is given, it displays the status of the given interface
only; if a single -a argument is given, it displays the status of all interfaces, even those
that are down. Otherwise, it configures an interface.
SYNOPSIS
ifconfig [-L] [-m] interface [create] [address_family] [address[/prefixlength]
[dest_address]]
[parameters]
ifconfig
interface
destroy
ifconfig
-a
[-L]
[-d]
[-m]
[-u]
[address_family]
ifconfig
-l
[-d]
[-u]
[address_family]
ifconfig [-L] [-d] [-m] [-u] [-C]
OPTIONS :
-a
Optionally, the -a flag may be used instead of an interface name. This flag instructs
ifconfig to display information about all interfaces in the system.
-d
The -d flag displays interfaces that are down. You can use the flag only with the -a or
-l
flag.
-l
This flag may be used to list all available interfaces on the system, with no other
additional information. Use of this flag is mutually exclusive with all other flags and
commands,
except
for
-d
and
-u.
-u
The -u flag displays interfaces that are up. You can use the flag only with the -a or -l
flag.
addressfamily This flag specifies protocols such as tcp, udp, tcp6, udp6, icmp, and
icmp6.
Parameters
alias
Establishes an additional network address for the interface. When changing network
numbers, this parameter is useful for accepting packets addressed to the old interface.
allcast
Sets the Token-Ring interface to broadcast to all rings on the network.
-allcast
Confines the Token-Ring interface to broadcast only to the local ring.
arp
Enables the ifconfig command to use the Address Resolution Protocol in mapping
between network-level addresses and link-level addresses. The arp value is the default.
-arp
Disables the use of the Address Resolution Protocol.
broadcast
Address
(inet only) Specifies the address to use to broadcast to the network. The default
broadcast address has a host part of all 1s.
checksum_offload
Enables the flag to indicate that transmit TCP checksum should be offloaded to the
adapter. The command will also reset the per-interface counter that determines
whether TCP should dynamically enable or disable offloading of checksum
computation.
-checksum_offload
Disables transmit TCP checksum offloading.
delete
Removes the specified network address. This is used when an alias is incorrectly
specified or when it is no longer needed. Incorrectly setting an ns address has the side
effect of specifying the host portion of the network address. Removing all ns
addresses allows you to re-specify the host portion.
detach
Removes an interface from the network interface list. If the last interface is detached,
the network interface driver code is unloaded. In order for the interface route of an
attached interface to be changed, that interface must be detached and added again with
ifconfig.
down
Marks an interface as inactive (down), which keeps the system from trying to transmit
messages through that interface. If possible, the ifconfig command also resets the
interface to disable reception of messages. Routes that use the interface, however, are
not automatically disabled.
group
ID
Adds a group ID to the group ID list for the interface. This list is used in determining
the route to use when forwarding packets that arrived on the interface.
-group
ID
Removes a group ID from the group ID list for the interface. This list is used in
determining the route to use when forwarding packets that arrived on the interface.
hwloop
Enables hardware loopback. The hardware loopback specifies that locally addressed
packets handled by an interface should be sent out using the associated adapter.
-hwloop
Disables hardware loop-back. The hardware loop-back specifies that locally addressed
packets handled by an interface should be sent out using the associated adapter.
ipdst
Specifies an Internet host willing to receive IP packets encapsulating ns packets bound
for a remote network. An apparent point-to-point link is constructed, and the specified
address is taken as the ns address and network of the destination.
metric
Number
Sets the routing metric of the interface to the value specified by the Number variable.
The default is 0 (zero). The routing metric is used by the routing protocol (the routed
daemon). Higher metrics have the effect of making a route less favorable. Metrics are
counted as addition hops to the destination network or host.
monitor
Enables the underlying adapter to notify the interface layer of link status changes. The
adapter must support link status callback notification. If multipath routing is used,
alternate
routes
are
selected
when
a
link
goes
down.
-monitor
Disables
adapter
link
status
monitoring.
mtu
Value
Sets the maximum IP packet size for this system. The Value variable can be any
number from 60 through 65535, but is media dependent. See Automatic configuration
of network interfaces in Networks and communication management for maximum
transmission unit (MTU) values by interface.
netmask
Mask
Specifies how much of the address to reserve for subdividing networks into
subnetworks. This parameter can be used only with an address family of inet.
up
Marks an interface as active (up). This parameter is used automatically when setting
the first address for an interface. It can also be used to enable an interface after an
ifconfig down command.
EXAMPLES
1. View All Network Setting
The ifconfig command with no arguments will display all the active interfaces
details.
# ifconfig
eth0
lo
tun0
lo
sit0
Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
tun0
OR
# ifup eth0
OR
# ifdown eth0
To assign an IP address, Netmask address and Broadcast address all at once using
ifconfig command with all arguments as given below.
# ifconfig eth0 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63
Next, verify the newly created alias network interface address, by using ifconfig
eth0:0 command.
# ifconfig eth0:0
eth0:0 Link encap:Ethernet HWaddr 00:01:6C:99:14:68
inet addr:172.16.25.123 Bcast:172.16.25.63 Mask:255.255.255.240
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:17
netstat Print network connections, routing tables, interface statistics, masquerade connections,
and multicast memberships
DESCRIPTION
netstat (network statistics) is a command line tool for monitoring network connections
both incoming and outgoing as well as viewing routing tables, interface statistics etc.
netstat is available on all Unix-like Operating Systems and also available on Windows
OS as well. It is very useful in terms of network troubleshooting and performance
measurement. netstat is one of the most basic network service debugging tools, telling
you what ports are open and whether any programs are listening on ports.
SYNOPSIS
netstat [-a] [-n] [-v]
netstat [-g | -m | -p | -s | -f address_family ] [-n] [-P protocol]
netstat [ -i ] [ -I interface ] [ interval ]
netstat -r [-a] [-n] [-v ]
netstat -M [-n] [-s ]
netstat -D [ -I interface ]
OPTIONS :
-a
Show the state of all sockets and all routing table entries; normally, sockets used by
server processes are not shown and only interface, host, network, and default routes are
shown.
-n
Show network addresses as numbers. netstat normally displays addresses as symbols.
This
option
may
be
used
with
any
of
the
display
formats.
-v
Verbose. Show additional information for the sockets and the routing table.
-g
Show
the
multicast
group
memberships
for
all
interfaces.
-m
Show
the
STREAMS
statistics.
-p
Show
the
address
resolution
(ARP)
tables.
-s
Show per-protocol statistics. When used with the -M option, show multicast routing
statistics
instead.
-i
Show
the
state
of
the
interfaces
that
are
used
for
TCP/IP
traffic.
-r
Show
the
routing
tables.
-M
Show the multicast routing tables. When used with the -s option, show multicast routing
statistics
instead.
-d
Show the state of all interfaces that are under Dynamic Host Configuration Protocol
(DHCP)
control.
-D
Show
the
status
of
DHCP
configured
-f
interfaces.
address_family
imit statistics or address control block reports to those of the specified address_family,
which
inet
can
For
be
the
AF_INET
one
address
of:
family
protocol
interface
Show the state of a particular interface. interface can be any valid interface such as ie0
or
le0.
EXAMPLES
1. Listing Various Listening Ports
Listing all the LISTENING Ports of TCP and UDP connections
# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address
Foreign Address
State
tcp
tcp
tcp
tcp
tcp
udp
udp
0
0
1
0
0
0
0
0 *:sunrpc
52 192.168.0.2:ssh
0 192.168.0.2:59292
0 localhost:smtp
0 *:59482
0 *:35036
0 *:npmp-local
*:*
LISTEN
192.168.0.1:egs
ESTABLISHED
www.gov.com:http
CLOSE_WAIT
*:*
LISTEN
*:*
LISTEN
*:*
*:*
/tmp/orbit-root/linc-76b-0-
STREAM
LISTENING
17149
/tmp/orbit-root/linc-794-0-
STREAM
LISTENING
17161
/tmp/orbit-root/linc-792-0-
STREAM
LISTENING
15938
/tmp/orbit-root/linc-74b-0-
State
Foreign Address
LISTEN
LISTEN
LISTEN
State
/tmp/orbit-root/linc-76b-0-
STREAM
LISTENING
17149
/tmp/orbit-root/linc-794-0-
STREAM
LISTENING
17161
/tmp/orbit-root/linc-792-0-
STREAM
LISTENING
15938
/tmp/orbit-root/linc-74b-0-
Address
State
LISTEN
LISTEN
LISTEN
LISTEN
LISTEN
LISTEN
LISTEN
LISTEN
LISTEN
LISTEN
Foreign Address
State
Genmask
Flags MSS Window irtt Iface
255.255.255.0 U
00
0 eth0
link-local
default
*
255.255.0.0
192.168.0.1
0.0.0.0
U
UG
00
00
0 eth0
0 eth0
tcp
tcp
tcp
tcp
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[]
*:http
*:*
LISTEN
9056/httpd
*:https
*:*
LISTEN
9056/httpd
tecmint.com:http sg2nlhg008.shr.prod.s:35248 TIME_WAIT
tecmint.com:http sg2nlhg007.shr.prod.s:57783 TIME_WAIT
tecmint.com:http sg2nlhg007.shr.prod.s:57769 TIME_WAIT
tecmint.com:http sg2nlhg008.shr.prod.s:35270 TIME_WAIT
tecmint.com:http sg2nlhg009.shr.prod.s:41637 TIME_WAIT
tecmint.com:http sg2nlhg009.shr.prod.s:41614 TIME_WAIT
STREAM
CONNECTED
88586726 10394/httpd
This tutorial explains Linux nslookup command, options and its usage with examples.
nslookup query Internet name servers interactively
DESCRIPTION
nslookup is a network administration tool for querying the Domain Name System (DNS)
to obtain domain name or IP address mapping or any other specific DNS record.
It is also used to troubleshoot DNS related problems. This article provides few examples
on using the nslookup command.
nslookup can operate on both Interactive mode and Non-Interactive mode. Interactive
mode allows the user to query the DNS-Server about various host, and domains. NonInteractive mode allows the user to query the information for a host or domain.
In this article, all the commands explained are Non-Interactive mode.
Authoritative Answer vs Non-Authoritative Answer
Any answer that originates from the DNS Server which has the complete zone file
information available for the domain is said to be authoritative answer.
In many cases, DNS servers will not have the complete zone file information available
for a given domain. Instead, it maintains a cache file which has the results of all queries
performed in the past for which it has gotten authoritative response. When a DNS query
is given, it searches the cache file, and return the information available as NonAuthoritative Answer.
SYNOPSIS
nslookup [ - option ] host [ server ]
OPTIONS
all
List the current settings
d2
Set exhaustive debug mode on
nod2
Set exhaustive debug mode off
debug
Set debug mode on
nodebug
Set debug mode off
defname
Set domain-appending mode on
nodefname
Set domain-appending mode off
domain=string
Establish the appendable domain
ignoretc
Set it to ignore packet truncation errors
noignoretc
Set it to acknowledge packet truncation errors
host
Inquires about the specified host. In this non-interactive command format, nslookup
Does not prompt for additional commands.
Causes nslookup to prompt for more information, such as host names, before sending
one or more queries.
server
Directs inquiries to the name server specified here in the command line rather than the
one read from the /etc/resolv.conf file. server can be either a name or an Internet
address. If the specified host cannot be reached, nslookup resorts to using the name
server specified in /etc/resolv.conf.
EXAMPLES
1. Simple Example
Looking up google.com
$ nslookup google.com
Server:
127.0.1.1
Address: 127.0.1.1#53
Non-authoritative answer:
Name: google.com
Address: 74.125.200.138
Name: google.com
Address: 74.125.200.113
Name: google.com
Address: 74.125.200.102
Name: google.com
Address: 74.125.200.100
Name: google.com
Address: 74.125.200.101
Name: google.com
Address: 74.125.200.139
answer:
mail exchanger
mail exchanger
mail exchanger
mail exchanger
mail exchanger
=
=
=
=
=
10
50
40
30
20
aspmx.l.google.com.
alt4.aspmx.l.google.com.
alt3.aspmx.l.google.com.
alt2.aspmx.l.google.com.
alt1.aspmx.l.google.com.
alt3.aspmx.l.google.com
ns2.google.com internet
ns3.google.com internet
ns4.google.com internet
ns1.google.com internet
Address: 173.194.36.7
Name: google.com
Address: 173.194.36.9
Name: google.com
Address: 173.194.36.2
Name: google.com
Address: 173.194.36.1
Name: google.com
Address: 173.194.36.8
Name: google.com
Address: 173.194.36.14
Name: google.com
Address: 173.194.36.3
Name: google.com
Address: 173.194.36.4
Name: google.com
Address: 173.194.36.6
Here you may notice that, we dont get any Non-authoritative answer: header, since
ns1.redhat.com has all the zone information of redhat.com