{"id":144139,"date":"2024-11-01T08:40:27","date_gmt":"2024-11-01T00:40:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/144139\/"},"modified":"2024-11-01T08:40:29","modified_gmt":"2024-11-01T00:40:29","slug":"ubuntu-%e4%b8%8b%e5%a6%82%e4%bd%95%e5%90%8c%e6%99%82-ping-%e4%ba%94%e5%80%8b%e4%b8%8d%e5%90%8c%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-ubuntu-ping-%e4%ba%94%e5%80%8b%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/144139\/","title":{"rendered":"Ubuntu \u4e0b\u5982\u4f55\u540c\u6642 ping \u4e94\u500b\u4e0d\u540c\u7684\u6578\u64da\u5eab\uff1f (ubuntu ping \u4e94\u500b\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"ubuntu-%e4%b8%8b%e5%a6%82%e4%bd%95%e5%90%8c%e6%99%82-ping-%e4%ba%94%e5%80%8b%e4%b8%8d%e5%90%8c%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-sDQbPWLpJC\">Ubuntu \u4e0b\u5982\u4f55\u540c\u6642 ping \u4e94\u500b\u4e0d\u540c\u7684\u6578\u64da\u5eab\uff1f<\/h1>\n<p>\u5728\u73fe\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u904b\u884c\u81f3\u95dc\u91cd\u8981\u3002\u7121\u8ad6\u662f\u958b\u767c\u8005\u9084\u662f\u7cfb\u7d71\u7ba1\u7406\u54e1\uff0c\u7d93\u5e38\u9700\u8981\u6aa2\u67e5\u6578\u64da\u5eab\u7684\u9023\u63a5\u72c0\u614b\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu \u7cfb\u7d71\u4e2d\u540c\u6642 ping \u4e94\u500b\u4e0d\u540c\u7684\u6578\u64da\u5eab\uff0c\u4ee5\u78ba\u4fdd\u5b83\u5011\u7684\u53ef\u7528\u6027\u548c\u97ff\u61c9\u6642\u9593\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-ping%ef%bc%9f-sDQbPWLpJC\">\u4ec0\u9ebc\u662f Ping\uff1f<\/h2>\n<p>Ping \u662f\u4e00\u7a2e\u7db2\u7d61\u8a3a\u65b7\u5de5\u5177\uff0c\u7528\u65bc\u6e2c\u8a66\u4e3b\u6a5f\u4e4b\u9593\u7684\u9023\u63a5\u6027\u3002\u5b83\u901a\u904e\u5411\u76ee\u6a19\u4e3b\u6a5f\u767c\u9001 ICMP\uff08Internet Control Message Protocol\uff09\u56de\u986f\u8acb\u6c42\uff0c\u4e26\u7b49\u5f85\u56de\u61c9\u4f86\u5de5\u4f5c\u3002Ping \u7684\u7d50\u679c\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u4e86\u89e3\u7db2\u7d61\u5ef6\u9072\u548c\u6578\u64da\u5eab\u7684\u53ef\u7528\u6027\u3002<\/p>\n<h2 id=\"%e6%ba%96%e5%82%99%e5%b7%a5%e4%bd%9c-sDQbPWLpJC\">\u6e96\u5099\u5de5\u4f5c<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u7d93\u5b89\u88dd\u4e86 Ubuntu \u7cfb\u7d71\uff0c\u4e26\u4e14\u53ef\u4ee5\u8a2a\u554f\u547d\u4ee4\u884c\u754c\u9762\u3002\u6b64\u5916\uff0c\u60a8\u9700\u8981\u77e5\u9053\u8981 ping \u7684\u6578\u64da\u5eab\u7684 IP \u5730\u5740\u6216\u57df\u540d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u6578\u64da\u5eab\u53ca\u5176\u9023\u63a5\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li>\u6578\u64da\u5eab 1: db1.example.com<\/li>\n<li>\u6578\u64da\u5eab 2: db2.example.com<\/li>\n<li>\u6578\u64da\u5eab 3: db3.example.com<\/li>\n<li>\u6578\u64da\u5eab 4: db4.example.com<\/li>\n<li>\u6578\u64da\u5eab 5: db5.example.com<\/li>\n<\/ul>\n<h2 id=\"%e5%90%8c%e6%99%82-ping-%e4%ba%94%e5%80%8b%e6%95%b8%e6%93%9a%e5%ba%ab-sDQbPWLpJC\">\u540c\u6642 Ping \u4e94\u500b\u6578\u64da\u5eab<\/h2>\n<p>\u5728 Ubuntu \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u591a\u500b\u65b9\u6cd5\u4f86\u540c\u6642 ping \u591a\u500b\u4e3b\u6a5f\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 Bash \u8173\u672c\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>#!\/bin\/bash\n\n# \u5b9a\u7fa9\u6578\u64da\u5eab\u7684\u57df\u540d\u6216 IP \u5730\u5740\ndatabases=(\"db1.example.com\" \"db2.example.com\" \"db3.example.com\" \"db4.example.com\" \"db5.example.com\")\n\n# \u5faa\u74b0\u904d\u6b77\u6bcf\u500b\u6578\u64da\u5eab\u4e26 ping\nfor db in \"${databases[@]}\"; do\n    ping -c 4 $db &amp; # \u4f7f\u7528 &amp; \u4f7f\u6bcf\u500b ping \u5728\u80cc\u666f\u4e2d\u904b\u884c\ndone\n\n# \u7b49\u5f85\u6240\u6709\u80cc\u666f\u9032\u7a0b\u5b8c\u6210\nwait\necho \"\u6240\u6709 ping \u64cd\u4f5c\u5df2\u5b8c\u6210\uff01\"\n<\/code><\/pre>\n<p>\u5728\u9019\u6bb5\u8173\u672c\u4e2d\uff0c\u6211\u5011\u9996\u5148\u5b9a\u7fa9\u4e86\u4e00\u500b\u6578\u7d44\uff0c\u5305\u542b\u4e94\u500b\u6578\u64da\u5eab\u7684\u5730\u5740\u3002\u7136\u5f8c\uff0c\u6211\u5011\u4f7f\u7528 for \u5faa\u74b0\u904d\u6b77\u6bcf\u500b\u6578\u64da\u5eab\uff0c\u4e26\u4f7f\u7528 ping \u547d\u4ee4\u767c\u9001\u56db\u500b\u8acb\u6c42\uff08-c 4 \u53c3\u6578\uff09\u3002\u6bcf\u500b ping \u64cd\u4f5c\u90fd\u5728\u80cc\u666f\u4e2d\u904b\u884c\uff0c\u9019\u6a23\u53ef\u4ee5\u5be6\u73fe\u540c\u6642 ping \u7684\u6548\u679c\u3002\u6700\u5f8c\uff0c\u6211\u5011\u4f7f\u7528 wait \u547d\u4ee4\u7b49\u5f85\u6240\u6709\u7684 ping \u64cd\u4f5c\u5b8c\u6210\u3002<\/p>\n<h2 id=\"%e5%88%86%e6%9e%90-ping-%e7%b5%90%e6%9e%9c-sDQbPWLpJC\">\u5206\u6790 Ping \u7d50\u679c<\/h2>\n<p>\u7576\u60a8\u904b\u884c\u4e0a\u8ff0\u8173\u672c\u6642\uff0c\u60a8\u5c07\u770b\u5230\u6bcf\u500b\u6578\u64da\u5eab\u7684 ping \u7d50\u679c\u3002\u9019\u4e9b\u7d50\u679c\u5c07\u986f\u793a\u6bcf\u500b\u6578\u64da\u5eab\u7684\u97ff\u61c9\u6642\u9593\u548c\u4e1f\u5305\u7387\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u7d50\u679c\u5206\u6790\uff1a<\/p>\n<ul>\n<li><strong>\u97ff\u61c9\u6642\u9593\uff1a<\/strong>\u5982\u679c\u97ff\u61c9\u6642\u9593\u8f03\u4f4e\uff08\u4f8b\u5982\u5c0f\u65bc 50ms\uff09\uff0c\u5247\u8868\u793a\u6578\u64da\u5eab\u7684\u9023\u63a5\u826f\u597d\u3002<\/li>\n<li><strong>\u4e1f\u5305\u7387\uff1a<\/strong>\u5982\u679c\u4e1f\u5305\u7387\u70ba 0%\uff0c\u5247\u8868\u793a\u6578\u64da\u5eab\u53ef\u7528\u6027\u9ad8\uff1b\u5982\u679c\u4e1f\u5305\u7387\u8f03\u9ad8\uff0c\u5247\u53ef\u80fd\u5b58\u5728\u7db2\u7d61\u554f\u984c\u3002<\/li>\n<li><strong>\u8d85\u6642\uff1a<\/strong>\u5982\u679c\u67d0\u500b\u6578\u64da\u5eab\u7684 ping \u64cd\u4f5c\u8d85\u6642\uff0c\u5247\u53ef\u80fd\u8868\u793a\u8a72\u6578\u64da\u5eab\u7121\u6cd5\u8a2a\u554f\u6216\u5b58\u5728\u6545\u969c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-sDQbPWLpJC\">\u7d50\u8ad6<\/h2>\n<p>\u5728 Ubuntu \u7cfb\u7d71\u4e2d\uff0c\u540c\u6642 ping \u591a\u500b\u6578\u64da\u5eab\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u76e3\u63a7\u6578\u64da\u5eab\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u3002\u901a\u904e\u4f7f\u7528 Bash \u8173\u672c\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u81ea\u52d5\u5316\u9019\u4e00\u904e\u7a0b\uff0c\u4e26\u5feb\u901f\u7372\u53d6\u6240\u9700\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu \u7cfb\u7d71\u4e2d\u540c\u6642 ping \u4e94\u500b\u4e0d\u540c\u7684\u6578\u64da\u5eab\uff0c\u78ba\u4fdd\u9023\u63a5\u7a69\u5b9a\u6027\u548c\u6027\u80fd\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-144139","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=144139"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144139\/revisions"}],"predecessor-version":[{"id":144140,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/144139\/revisions\/144140"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=144139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=144139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=144139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}