Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

ping

Send ICMP echo requests to a host to test if it is reachable and how fast it answers.

Niveau
RHCSA-examen
Groep
Netwerk
Root nodig
Nee
Pakket
iputils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

ping sends small packets and waits for the answer. It shows the round-trip time per packet and at the end the packet loss and min/avg/max times. On Linux it runs until you press Ctrl+C, unless you give a count with -c.

No answer does not always mean the host is down: firewalls often block ICMP. Test the real service too (like curl or ss).

Zo schrijf je het

ping [OPTION]... DESTINATION

Opties 38

Meest gebruikt

Count and timing

-c COUNT
Stop after COUNT packets.
-i INTERVAL
Seconds between packets (default 1; under 0.2 only for root).
-w DEADLINE
Stop after this many seconds, whatever happens.
-W TIMEOUT
Wait this long for each answer.
-f
Flood ping: send as fast as possible (root only; shows dots).
-l PRELOAD
Send this many packets without waiting first.

Address and route

-4
Use IPv4 only.
-6
Use IPv6 only.
-I INTERFACE
Send from this interface or source address.
-b
Allow ping to a broadcast address.
-r
Do not use the routing table; send directly on the interface.
-R
Record the route (IPv4, most hosts ignore it).
-m MARK
Set a firewall mark on the packets.
-Q TOS
Set the Type of Service / DSCP bits.
-t TTL
Set the time to live.
-F FLOWLABEL
Set the IPv6 flow label.
-N NODEINFO_OPTION
Send IPv6 node info queries.

Packets

-s SIZE
Data bytes per packet (default 56 = 84 bytes with headers).
-M DO|WANT|DONT|PROBE
Path MTU discovery: do = do not fragment.
-p PATTERN
Fill the packet with this hex pattern.
-S SNDBUF
Socket send buffer.
-T TIMESTAMP_OPTION
IP timestamp option (tsonly, tsandaddr, tsprespec).
-e IDENTIFIER
The ICMP identifier.

Output

-q
Quiet: only the summary at the end.
-n
Numbers only, no name lookups for the replies.
-a
Beep for every answer.
-A
Adaptive: next packet as soon as the answer comes.
-D
Print a time stamp before each line.
-O
Report missing answers before the next packet.
-U
Print full user-to-user latency.
-v
Verbose.
-d
Set SO_DEBUG on the socket.
-B
Do not change the source address.
-C
Call connect() on the socket.
-L
Do not loop multicast packets back.
-H
Force DNS name resolution for output.
-h
Show help.
-V
Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Test a host with 3 packets

    ping -c 3 192.168.122.1
    PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data.
    64 bytes from 192.168.122.1: icmp_seq=1 ttl=64 time=0.412 ms
    64 bytes from 192.168.122.1: icmp_seq=2 ttl=64 time=0.389 ms
    64 bytes from 192.168.122.1: icmp_seq=3 ttl=64 time=0.401 ms
     
    --- 192.168.122.1 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 0.389/0.400/0.412/0.009 ms

    0% loss = the gateway answers.

  2. 2Test the network step by step

    ping -c1 192.168.122.1 && ping -c1 8.8.8.8 && ping -c1 www.redhat.com

    Gateway → internet → DNS: the first failure shows where the problem is.

  3. 3Test IPv6

    ping -6 -c 2 2001:db8:10::1

    Use -6 with names that have both addresses.

  4. 4Ping from a chosen interface

    ping -c 3 -I enp2s0 10.0.0.1

    Checks a second network card.

  5. 5Find the MTU of the path

    ping -c 2 -M do -s 1472 192.168.122.20

    1472 + 28 header bytes = 1500. "Message too long" means the MTU is smaller (VPN, tunnels).

  6. 6Only the summary

    ping -q -c 20 server2

    Good for scripts and reports.

  7. 7Stop after a fixed time

    ping -w 5 server2

    Ends after 5 seconds even when no answer comes.

  8. 8Wait until a host is back after a reboot

    until ping -c1 -W1 server2 >/dev/null; do sleep 2; done; echo "server2 is up"

    Then connect with ssh.

  9. 9Log with time stamps

    ping -D -i 10 server2 | tee ping.log

    Proof of short outages for the network team.

  10. 10Quick sweep of a small subnet

    for i in $(seq 1 20); do ping -c1 -W1 192.168.122.$i >/dev/null && echo "192.168.122.$i up"; done

    Only on your own networks; better tools: nmap -sn.

  11. 11Load test (root, lab only)

    ping -f -c 1000 server2

    Shows packet loss under load. Never on networks you do not own.

Let op

  • No answer can be a firewall, not a dead host.
  • A name that does not resolve gives "Name or service not known": that is a DNS problem.

Exitcodes

0 :: At least one answer. 1 :: No answer (with -c or -w). 2 :: Other error (like an unknown name).