Linux ping по http

Проверка доступности сайта из Linux

Несколько полезных команд, позволяющих быстро выполнить диагностику сайта.

Ping

Это самый простой вариант:

$ ping pctuner.club PING pctuner.club (31.184.252.207) 56(84) bytes of data. 64 bytes from d1mon.com (31.184.252.207): icmp_seq=1 ttl=55 time=36.1 ms 64 bytes from d1mon.com (31.184.252.207): icmp_seq=2 ttl=55 time=37.3 ms 64 bytes from d1mon.com (31.184.252.207): icmp_seq=3 ttl=55 time=36.9 ms 64 bytes from d1mon.com (31.184.252.207): icmp_seq=4 ttl=55 time=36.2 ms ^C --- pctuner.club ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3004ms rtt min/avg/max/mdev = 36.136/36.670/37.333/0.509 ms

Показывает не только доступность сайта, но и собирает статистику, насколько связь с сайтом качественная. Статистика собирается до тех пор, пока вы сами это не остановите, «Ctrl+C».

Traceroute

Если ответы от сайта приходят с заметной задержкой или иногда не приходят вовсе, то бывает полезно посмотреть весь маршрут. Утилита traceroute — аналог tracert в Windows.

$ traceroute pctuner.club traceroute to pctuner.club (31.184.252.207), 30 hops max, 60 byte packets 1 192.168.254.1 (192.168.254.1) 5.119 ms 7.653 ms 8.916 ms 2 192.168.249.1 (192.168.249.1) 7.302 ms 8.334 ms 10.421 ms 3 212.46.230.25 (212.46.230.25) 11.045 ms 12.726 ms 12.731 ms 4 pe26.Moscow.gldn.net (79.104.225.59) 28.446 ms pe26.Moscow.gldn.net (79.104.225.57) 29.417 ms 30.821 ms 5 mx.vicigroup.ru (194.186.124.146) 35.698 ms 35.692 ms 35.666 ms 6 80-64-100-81.rascom.as20764.net (80.64.100.81) 39.825 ms 80-64-100-97.rascom.as20764.net (80.64.100.97) 36.661 ms 80-64-100-82.rascom.as20764.net (80.64.100.82) 32.558 ms 7 81-27-252-147.rascom.as20764.net (81.27.252.147) 35.306 ms 46.628 ms 37.286 ms 8 188.93.17.137 (188.93.17.137) 36.900 ms 34.609 ms 33.725 ms 9 d1mon.com (31.184.252.207) 42.136 ms 34.529 ms 34.517 ms

Установка в Ubuntu/Debian, если утилиты еще нет в системе:

sudo apt install inetutils-traceroute

cURL

Позволяет не только проверить доступность, но и получить код состояния:

$ curl -Is https://pctuner.club | head -n 1 HTTP/2 200
$ curl -Is http://pctuner.club | head -n 1 HTTP/1.1 301 Moved Permanently

Аналогично на сайте можно проверить доступность страницы или файла:

$ curl -Is https://pctuner.club/robots.txt | head -n 1 HTTP/2 200

Источник

Linux Ping Command Tutorial with Examples

Most Linux users are familiar with the ping command and know how to use it in its basic form. However, there are many additional ping options and variations. In this guide, we will walk you through some of the most useful Linux ping commands with examples.

Читайте также:  Открытие всех портов linux

The commands in this article work with any UNIX or Linux distribution. The test system we used to provide the examples and output samples is Ubuntu 18.04.2 LTS.

linux ping command tutorial

  • Linux or UNIX-like system
  • Access to a terminal
  • A user with the necessary permissions to run the commands

How ping Works in Linux

The Linux ping command is a simple utility used to check whether a network is available and if a host is reachable. With this command, you can test if a server is up and running. It also helps with troubleshooting various connectivity issues.

The ping command allows you to:

  • Test your internet connection.
  • Check if a remote machine is online.
  • Analyze if there are network issues, such as dropped packages or high latency.

When you try to “ping” a remote host, your machine starts sending ICMP echo requests and waits for a response. If the connection is established, you receive an echo reply for every request.

The output for the ping command contains the amount of time it takes for every packet to reach its destination and return.

The terminal keeps printing the responses until interrupted. After every session, there are a few lines with ping statistics.

output of the linux ping command

How to Use the ping Command

The basic ping syntax includes ping followed by a hostname, a name of a website, or the exact IP address.

ping [option] [hostname] or [IP address]

Hence, to check whether a remote host is up, in this case, google.com, type in your terminal:

Press Ctrl + C on your keyboard to stop the process.

diagram of how pink works in Linux

1. from : The destination and its IP address. Note that the IP address may be different for a website depending on your geographical location.

2. icmp_seq=1 : The sequence number of each ICMP packet. Increases by one for every subsequent echo request.

3. ttl=52 : The Time to Live value from 1 to 255. It represents the number of network hops a packet can take before a router discards it.

4. time=7.68 ms : The time it took a packet to reach the destination and come back to the source. Expressed in milliseconds.

ping Commands in Linux with Examples

ping “localhost” to Check Local Network

If you encounter issues reaching a website or a remote machine, you can ping localhost to confirm you have a network connection. Use one of the three ways to check the local network interface:

  1. ping 0 – This is the quickest way to ping localhost. Once you type this command, the terminal resolves the IP address and provides a response.
  2. ping localhost – You can use the name to ping localhost. The name refers to your computer, and when we use this command, we say: “ping this computer.”
  3. ping 127.0.0.1 – Some people prefer using the IP address 127.0.0.1 to ping localhost.

Whichever method you choose, the ping output looks the same.

Читайте также:  Jcp linux control panel

Specify the Internet Protocol

IPv6 is the IP address alphanumeric format that will supersede IPv4. The reason for this is there is a limited number of IPv4 address, and we are running out of possible combinations.

To request IPv6 or IPv4 address, add -6 or -4 after the ping command and before a hostname/IP.

Change Time Interval Between Ping Packets

The default interval between each ping request is set to one second. You can increase or decrease that time using the -i switch. To decrease the ping interval, use values lower than 1.

To increase the ping interval, enter any value higher than 1.

Change Ping Packet Size

In some scenarios, you may want to use -s to increase the packet size from the default value of 56 (84) bytes. The number in parenthesis represents the ping bytes sent including 28 bytes of the header packet.

For example, to increase the packet size to 1000 bytes:

increasing the packet size to 1000 example

This command is useful when testing network performance. You can test if a network link throttles when you increase the packet size to a few thousand bytes.

Flood a Network Using ping to Test Performance

You can use ping flood to test your network performance under heavy load.

Ping flood -f option requires root to execute. Otherwise, apply sudo to your ping command to flood a host. This command sends a large number of packets as soon as possible.

Testing network performance with ping flood.

The output prints a dot for every sent package, and a backspace for every response. The statistics line shows a summary of the ping command.

How to Limit the Number of Pings

The default setting for the ping command is to keep sending the request until you interrupt it. You can limit the number of pings using one of the two methods.

Limit Number of Ping Packets

To make the ping command automatically stop after it sends a certain number of packets, use -c and a number. This sets the desired amount of ping requests, as shown in this example:

sets the amount of ping requests

As you can see on the image above, the ping command stopped sending packets after two requests.

Set Time Limit for ping Command

To stop receiving a ping output after a specific amount of time, add -w and an interval in seconds to your command.

For example, to stop printing ping results after 25 seconds, enter the ping command:

Other Uses for ping

Suppress Ping Output to Print only Summary Statistics

If you do not want to clog your screen with information for every packet, use the -q switch to display the summary only.

The -q option prints one line with the regular ping information and then provides the statistics at the end. The letter “q” in this command stands for “quiet” output.

Читайте также:  Смена мандатной метки astra linux

We usually combine the quiet output with other options. In this case, we will limit the ping to send 10 packets and suppress the output.

limit the ping to send 10 packets and suppress the output

Add Timestamp Before Each Line in ping Output

If you want to note the time of day when you execute the ping command, add the -D option.

This prints a timestamp in UNIX format before each line.

print timestamp in UNIX format before each line

Note: You need to use uppercase D, as these commands are case sensitive.

Get an Audible Ping When a Host is Reachable

When you use the -a switch, the system plays a sound when there is a response from a host.

An audible ping is useful when you are troubleshooting network issues and do not want to look at the screen until there is a response.

The output looks the same as a regular ping command output.

Show Ping Version and Exit

At any time, you can check the version of the ping tool on your system.

Append -V to the ping command to display the version of this utility.

check the version of the ping tool

Commonly used Ping Commands include:

Ping Option What The Command Does
a Generates a sound when the peer can be reached.
b Allows to ping a broadcast IP address.
B Prevents the ping to change the source address of the probe.
c (count) Limits the number of sent ping requests.
d Sets the SO-DEBUG option on the used socket.
f Floods the network by sending hundreds of packets per second.
i (interval) Specifies an interval between successive packet transmissions. The default value is one second.
I (interface address) Sets the source IP address to the specified interface IP address. The option is required when pinging IPv6 link local address. You can use an IP address or name of the device.
l (preload) Defines the number of packets to send without waiting for a reply. To specify a value higher than 3, you need superuser permissions.
n Displays IP addresses in the ping output rather than hostnames.
q Shows a quiet output. One ping line is displayed and the summary of the ping command at the end.
T (ttl) Sets the Time To Live.
v Provides verbose output.
V Displays the ping version and exits to a new command prompt line.
w (deadline) Specifies a time limit before the ping command exits, regardless of how many packets have been sent or received.
W (timeout) Determines the time, in seconds, to wait for a response.

Now you know how to use the Linux ping command. The examples in the tutorial should help you understand how to use “ping” on a day-to-day basis.

Ping helps you check the network connectivity both locally and with a remote host.

To view the complete list with the remaining ping options, run the man command man ping inside the terminal.

Источник

Оцените статью
Adblock
detector