{"id":234874,"date":"2022-02-03T08:21:46","date_gmt":"2022-02-03T00:21:46","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=234874"},"modified":"2022-01-25T22:22:53","modified_gmt":"2022-01-25T14:22:53","slug":"linux-tcp-test","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-tcp-test.html","title":{"rendered":"Linux\u4e0b\u7684TCP\u6d4b\u8bd5\u5de5\u5177"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\ntcpping\u4f5c\u4e3a shell \u811a\u672c\u5b9e\u73b0\uff0c\u8be5\u811a\u672c\u54cd\u5e94\u5916\u90e8\u5de5\u5177\u6765\u6267\u884c\u548c\u62a5\u544a RTT \u6d4b\u91cf\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u5b89\u88c5tcpping\uff0c\u4f60\u9996\u5148\u9700\u8981\u5148\u5b89\u88c5\u8fd9\u4e9b\u5148\u51b3\u6761\u4ef6\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5982\u4f55\u5728 Linux \u4e0a\u5b89\u88c5 tcpping<\/strong><\/div>\n

\u6d4b\u91cf\u5230\u8fdc\u7a0b\u4e3b\u673a\u7684\u7f51\u7edc\u5ef6\u8fdf\u7684\u4e00\u79cd\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528ping\u5e94\u7528\u7a0b\u5e8f\u3002\u8be5ping\u5de5\u5177\u4f9d\u8d56 ICMP ECHO \u8bf7\u6c42\u548c\u56de\u590d\u6570\u636e\u5305\u6765\u6d4b\u91cf\u8fdc\u7a0b\u4e3b\u673a\u7684\u5f80\u8fd4\u5ef6\u8fdf\u3002\u4f46\u662f\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0cICMP \u6d41\u91cf\u53ef\u80fd\u4f1a\u88ab\u9632\u706b\u5899\u963b\u6b62\uff0c\u8fd9\u4f7f\u5f97\u8be5ping\u5e94\u7528\u7a0b\u5e8f\u5bf9\u4e8e\u53d7\u9650\u5236\u7684\u9632\u706b\u5899\u540e\u9762\u7684\u4e3b\u673a\u6beb\u65e0\u7528\u5904\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u5c06\u9700\u8981\u4f9d\u8d56\u4f7f\u7528 TCP\/UDP \u6570\u636e\u5305\u7684\u7b2c 3 \u5c42\u6d4b\u91cf\u5de5\u5177\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u7b2c 3 \u5c42\u6570\u636e\u5305\u66f4\u6709\u53ef\u80fd\u7ed5\u8fc7\u5e38\u89c1\u7684\u9632\u706b\u5899\u89c4\u5219\u3002<\/p>\n

\u4e00\u79cd\u8fd9\u6837\u7684\u7b2c 3 \u5c42\u6d4b\u91cf\u5de5\u5177\u662ftcpping. \u4e3a\u4e86\u6d4b\u91cf\u5ef6\u8fdf\uff0ctcpping\u5229\u7528\u6240\u8c13\u7684\u534a\u5f00\u653e\u8fde\u63a5\u6280\u672f\uff0c\u57fa\u4e8e TCP \u4e09\u8def\u63e1\u624b\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u901a\u8fc7\u7aef\u53e3\u53f7\uff08\u9ed8\u8ba4\u4e3a 80\uff09\u5411\u8fdc\u7a0b\u4e3b\u673a\u53d1\u9001 TCP SYN \u6570\u636e\u5305\u3002\u5982\u679c\u8fdc\u7a0b\u4e3b\u673a\u6b63\u5728\u4fa6\u542c\u8be5\u7aef\u53e3\uff0c\u5b83\u5c06\u4ee5 TCP ACK \u6570\u636e\u5305\u54cd\u5e94\u3002\u5426\u5219\uff0c\u5b83\u5c06\u4ee5 TCP RST \u6570\u636e\u5305\u54cd\u5e94\u3002\u65e0\u8bba\u54ea\u79cd\u65b9\u5f0f\uff0ctcpping\u90fd\u53ef\u4ee5\u901a\u8fc7\u5b9a\u65f6\u4f20\u51fa SYN \u6570\u636e\u5305\u548c\u4f20\u5165 ACK\uff08\u6216 RST\uff09\u6570\u636e\u5305\u6765\u6d4b\u91cf\u8fdc\u7a0b\u4e3b\u673a\u7684\u5f80\u8fd4\u65f6\u95f4 (RTT) \u5ef6\u8fdf\u3002<\/p>\n

\u5728 Linux \u4e0a\u5b89\u88c5tcpping<\/strong><\/div>\n

tcpping\u4f5c\u4e3a shell \u811a\u672c\u5b9e\u73b0\uff0c\u8be5\u811a\u672c\u54cd\u5e94\u5916\u90e8\u5de5\u5177\u6765\u6267\u884c\u548c\u62a5\u544a RTT \u6d4b\u91cf\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u5b89\u88c5tcpping\uff0c\u4f60\u9996\u5148\u9700\u8981\u5148\u5b89\u88c5\u8fd9\u4e9b\u5148\u51b3\u6761\u4ef6\u3002<\/p>\n

\u5b89\u88c5\u4f9d\u8d56 tcptraceroute<\/strong><\/span><\/div>\n

\u8981\u5728 Ubuntu \u6216 Debian \u4e0a\u5b89\u88c5tcptraceroute\uff1a<\/p>\n

\r\n$ sudo apt-get install tcptraceroute\r\n<\/pre>\n

\u8981\u5728 CentOS \u6216 RHEL \u4e0a\u5b89\u88c5tcptraceroute\uff0c\u9996\u5148\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u8bbe\u7f6e RepoForge\uff0c\u7136\u540e\u8fd0\u884c\uff1a<\/p>\n

\r\n$ sudo yum install tcptraceroute\r\n<\/pre>\n
\u5b89\u88c5\u4f9d\u8d56 bc<\/strong><\/span><\/div>\n

\u4f7f\u7528\u7684\u53e6\u4e00\u4e2a\u5de5\u5177tcpping\u662fGNUbc\uff0c\u5b83\u9884\u88c5\u5728\u6240\u6709\u4e3b\u8981\u7684 Linux \u53d1\u884c\u7248\u4e0a\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60tcpping\u5728\u6700\u5c0f Linux \u8fd0\u884c\u65f6\u73af\u5883\uff08\u4f8b\u5982Docker\u5bb9\u5668\u3001AWS \u6700\u5c0f\u6620\u50cf AMI\uff09\u4e2d\u8fd0\u884c\uff0c\u5219bc\u53ef\u80fd\u4e0d\u4f1a\u9884\u5148\u5b89\u88c5\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u9700\u8981bc\u81ea\u5df1\u5b89\u88c5\u3002<\/p>\n

\u5728Debian \u7684 Linux \u4e0a\u5b89\u88c5\uff1a<\/p>\n

\r\n$ sudo apt-get install bc\r\n<\/pre>\n

\u5728 Red Hat \u7684 Linux \u4e0a\u5b89\u88c5\uff1a<\/p>\n

\r\n$ sudo yum install bc\r\n<\/pre>\n
\u5b89\u88c5 tcpping<\/strong><\/span><\/div>\n

\u5b89\u88c5\u8fd9\u4e9b\u5fc5\u5907\u5de5\u5177\u540e\uff0c\u6700\u540e\u7ee7\u7eedtcpping\u4ece\u5b98\u65b9\u6e90\u4e0b\u8f7d\u3002<\/p>\n

\r\n$ wget http:\/\/www.vdberg.org\/~richard\/tcpping    \r\n$ cp tcpping \/usr\/bin    \r\n$ chmod 755 tcpping\r\n<\/pre>\n
\u4f7f\u7528tcpping\u6765\u8861\u91cf\u5ef6\u8fdf<\/strong><\/span><\/div>\n

\u8981\u4f7f\u7528 \u6d4b\u91cf\u7f51\u7edc\u5ef6\u8fdftcpping\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u683c\u5f0f\u3002<\/p>\n

\r\ntcpping [-d] [-c] [-r sec] [-x count] ipaddress [\u7aef\u53e3]\r\n<\/pre>\n
    \n-d: \u5728\u6bcf\u4e2a\u7ed3\u679c\u4e4b\u524d\u6253\u5370\u65f6\u95f4\u6233\u3002
    \n-c: \u4f7f\u7528\u5206\u5217\u8f93\u51fa\u4ee5\u4fbf\u4e8e\u89e3\u6790\u3002
    \n-r\uff1a\u8fde\u7eed\u63a2\u6d4b\u4e4b\u95f4\u7684\u95f4\u9694\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\uff08\u9ed8\u8ba4\u4e3a 1 \u79d2\uff09\u3002
    \n-x: \u91cd\u590d n \u6b21\uff08\u9ed8\u8ba4\u65e0\u9650\u5236\uff09\u3002
    \n[port]: \u76ee\u6807\u7aef\u53e3\uff08\u9ed8\u8ba4\u4e3a 80\uff09\u3002\n<\/ol>\n

    \u8bf7\u6ce8\u610f\uff0c\u4f60\u9700\u8981 root \u6743\u9650\u624d\u80fd\u8fd0\u884c\uff0ctcpping\u56e0\u4e3a\u5b83\u9700\u8981\u8c03\u7528\u7279\u6743tcptraceroute\u547d\u4ee4\u3002<\/p>\n

    \u5bf9\u4e8e\u4efb\u4f55\u5f00\u653e 80 \u7aef\u53e3\u7684\u76ee\u6807 Web \u670d\u52a1\u5668\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6d4b\u91cf\u5176 RTT \u5ef6\u8fdftcpping\u3002<\/p>\n

    \r\ntcpping www.rumenz.com  \r\nseq 0: tcp response from 42.194.162.109 (42.194.162.109)   33.822 ms  \r\ntraceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  \r\nseq 1: tcp response from 42.194.162.109 (42.194.162.109)   33.975 ms  \r\ntraceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  \r\nseq 2: tcp response from 42.194.162.109 (42.194.162.109)   32.010 ms  \r\ntraceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  \r\nseq 3: tcp response from 42.194.162.109 (42.194.162.109)   32.209 ms  \r\ntraceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  \r\nseq 4: tcp response from 42.194.162.109 (42.194.162.109)   30.866 ms  \r\ntraceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  \r\nseq 5: tcp response from 42.194.162.109 (42.194.162.109)   34.866 ms  \r\ntraceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  \r\nseq 6: tcp response from 42.194.162.109 (42.194.162.109)   32.604 ms  \r\ntraceroute to rumenz.com (42.194.162.109), 255 hops max, 60 byte packets  \r\nseq 7: tcp response from 42.194.162.109 (42.194.162.109)   30.495 ms\r\n\r\n<\/pre>\n

    \u5bf9\u4e8e\u4efb\u610f\u8fdc\u7a0b\u4e3b\u673a\uff0c\u5728\u8fd0\u884ctcpping. \u8981\u68c0\u67e5\u8fdc\u7a0b TCP \u7aef\u53e3\u662f\u5426\u6253\u5f00\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528nc\u5982\u4e0b\u547d\u4ee4\u3002<\/p>\n

    \r\n$ nc -vn  \r\n<\/port-number><\/ip-address><\/pre>\n

    -t: \u8fde\u7eed TCPing \uff0c\u76f4\u5230\u4f7f\u7528 Ctrl+C \u952e\u505c\u6b62<\/p>\n

    \r\ntcping -t 1.1.1.1 80\r\n<\/pre>\n

    -w 0.5: \u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\u4e3a 0.5\u79d2\uff081\u79d2=1000\u6beb\u79d2\uff09\uff0c\u5355\u4f4d \u79d2<\/p>\n

    \r\ntcping -w 0.5 1.1.1.1 80\r\n<\/pre>\n

    -s: \u5f53 TCPing \u6d4b\u8bd5\u6210\u529f\u540e\uff08\u5728\u8d85\u65f6\u65f6\u95f4\u4ee5\u5185\u8fd4\u56de TCPing \u5ef6\u8fdf\u6570\u636e\uff09\u81ea\u52a8\u505c\u6b62 TCPing<\/p>\n

    \r\ntcping -s 1.1.1.1 80\r\n<\/pre>\n

    -4: \u4f18\u5148 IPv4\uff08\u5982\u679c\u4e00\u4e2a\u57df\u540d\u6709 IPv4 \u548c IPv6 \u89e3\u6790\uff0c\u90a3\u4e48\u8d70 IPv4\uff09<\/p>\n

    \r\ntcping -s 1.1.1.1 80\r\n<\/pre>\n

    --file: TCPing \u5c06\u9010\u884c\u5faa\u73af\u904d\u5386\u6587\u4ef6\u5185\u7684 \u670d\u52a1\u5668IP\/\u57df\u540d \u4fe1\u606f\uff08\u4e00\u884c\u4e00\u4e2a\uff0c\u652f\u6301\u7aef\u53e3\uff0c\u4f8b\u5982\uff1a1.1.1.1 443\uff09<\/p>\n

    \r\ntcping --file rumenz.txt\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

    \u6d4b\u91cf\u5230\u8fdc\u7a0b\u4e3b\u673a\u7684\u7f51\u7edc\u5ef6\u8fdf\u7684\u4e00\u79cd\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528ping\u5e94\u7528\u7a0b\u5e8f\u3002\u8be5ping\u5de5\u5177\u4f9d\u8d56 ICMP ECHO \u8bf7\u6c42\u548c\u56de […]<\/p>\n","protected":false},"author":370,"featured_media":40536,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-234874","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/370"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=234874"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234874\/revisions"}],"predecessor-version":[{"id":234878,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234874\/revisions\/234878"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/40536"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=234874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=234874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=234874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}