Typically, there are two ways to detect network connectivity for Linux systems:
1. Through "ping command + Destination IP" or "Ping + target IP domain"
Note IP network detection for IPV6 address need to try ping6, while ping6 can not use parameter hops, because the IP6 source has abandoned the route, see the following English explanation:
Synopsis
ping [-AABBDDFHLNOQRRUVV] [-C Count] [-f Flowlabel] [-I interval] [-I interface] [-l preload] [-m mark] [-M Pmtudisc_opti On] [-N nodeinfo_option]
[-W Deadline] [-w timeout] [-P pattern] [-Q TOS] [-S PacketSize] [-S SNDBUF] [-t TTL] [-t timestamp option] [Hop ...] Destinationt.
Notes:
Ping6 is IPv6 version of Ping, and can also send Node information Queries (RFC4620). Intermediate hops May is allowed, because IPV6 source
Routing was deprecated.
Common parameters for ping instruction invocation:
# Parameter:
#-C The number of packages to send
#-I internel between-packages
#-W Timeout seconds
# Check The Connect status of Internetfunction Check_ip_status () { ping-c 3-i 0.2-w 3 $ &>/dev/null If [$?-eq 0];then return 0 else return-1 fi}if (' $ (check_ip_status 10.74.120.104)-ne 0 '); then Echo "Cannot connect guestconf server:10.74.120.104" Exit-1fi
2. Use "Curl Command + IP domain name"
#!/usr/bin/bash # #检测网络链接 &&ftp upload data function networkandftp () { #超时时间 timeout=5 #目标域名 target=www.baidu.com #获取响应状态码 ret_code= ' curl-i-S--connect-timeout $timeout $target-W%{ Http_code} | Tail-n1 ' if ["X$ret_code" = "x200"]; then #网络畅通 else #网络不畅通 fi
Detection of network connectivity using shell script function