{"id":261626,"date":"2023-02-14T09:43:17","date_gmt":"2023-02-14T01:43:17","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=261626"},"modified":"2023-01-16T15:22:04","modified_gmt":"2023-01-16T07:22:04","slug":"linux-tun-tap","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-tun-tap.html","title":{"rendered":"\u4ecb\u7ecdLinux\u4e0b\u7684 Tun\/Tap"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u5728\u8ba1\u7b97\u673a\u7f51\u7edc\u4e2d\uff0cTUN\u4e0eTAP\u662f\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u4e2d\u7684\u865a\u62df\u7f51\u7edc\u8bbe\u5907\u3002\u4e0d\u540c\u4e8e\u666e\u901a\u9760\u786c\u4ef6\u7f51\u8def\u677f\u5361\u5b9e\u73b0\u7684\u8bbe\u5907\uff0c\u8fd9\u4e9b\u865a\u62df\u7684\u7f51\u7edc\u8bbe\u5907\u5168\u90e8\u7528\u8f6f\u4ef6\u5b9e\u73b0\uff0c\u5e76\u5411\u8fd0\u884c\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7684\u8f6f\u4ef6\u63d0\u4f9b\u4e0e\u786c\u4ef6\u7684\u7f51\u7edc\u8bbe\u5907\u5b8c\u5168\u76f8\u540c\u7684\u529f\u80fd\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u4ec0\u4e48\u662fTun\/Tap<\/strong><\/div>\n TAP\u7b49\u540c\u4e8e\u4e00\u4e2a\u4ee5\u592a\u7f51\u8bbe\u5907\uff0c\u5b83\u64cd\u4f5c\u7b2c\u4e8c\u5c42\u6570\u636e\u5305\u5982\u4ee5\u592a\u7f51\u6570\u636e\u5e27\u3002TUN\u6a21\u62df\u4e86\u7f51\u7edc\u5c42\u8bbe\u5907\uff0c\u64cd\u4f5c\u7b2c\u4e09\u5c42\u6570\u636e\u5305\u6bd4\u5982IP\u6570\u636e\u5c01\u5305\u3002<\/p>\n \u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7TUN\/TAP\u8bbe\u5907\u5411\u7ed1\u5b9a\u8be5\u8bbe\u5907\u7684\u7528\u6237\u7a7a\u95f4\u7684\u7a0b\u5e8f\u53d1\u9001\u6570\u636e\uff0c\u53cd\u4e4b\uff0c\u7528\u6237\u7a7a\u95f4\u7684\u7a0b\u5e8f\u4e5f\u53ef\u4ee5\u50cf\u64cd\u4f5c\u786c\u4ef6\u7f51\u7edc\u8bbe\u5907\u90a3\u6837\uff0c\u901a\u8fc7TUN\/TAP\u8bbe\u5907\u53d1\u9001\u6570\u636e\u3002\u5728\u540e\u79cd\u60c5\u51b5\u4e0b\uff0cTUN\/TAP\u8bbe\u5907\u5411\u64cd\u4f5c\u7cfb\u7edf\u7684\u7f51\u7edc\u6808\u6295\u9012\uff08\u6216\u201c\u6ce8\u5165\u201d\uff09\u6570\u636e\u5305\uff0c\u4ece\u800c\u6a21\u62df\u4ece\u5916\u90e8\u63a5\u53d7\u6570\u636e\u7684\u8fc7\u7a0b\u3002<\/p>\n \u5e94\u7528\u7a0b\u5e8f\u5982\u4f55\u64cd\u4f5cTun\/Tap<\/strong><\/div>\n Linux Tun\/Tap\u9a71\u52a8\u7a0b\u5e8f\u4e3a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u4e24\u79cd\u4ea4\u4e92\u65b9\u5f0f\uff1a\u865a\u62df\u7f51\u7edc\u63a5\u53e3\u548c\u5b57\u7b26\u8bbe\u5907\/dev\/net\/tun\u3002\u5199\u5165\u5b57\u7b26\u8bbe\u5907\/dev\/net\/tun\u7684\u6570\u636e\u4f1a\u53d1\u9001\u5230\u865a\u62df\u7f51\u7edc\u63a5\u53e3\u4e2d\uff1b\u53d1\u9001\u5230\u865a\u62df\u7f51\u7edc\u63a5\u53e3\u4e2d\u7684\u6570\u636e\u4e5f\u4f1a\u51fa\u73b0\u5728\u8be5\u5b57\u7b26\u8bbe\u5907\u4e0a\u3002<\/p>\n \u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7\u6807\u51c6\u7684Socket API\u5411Tun\/Tap\u63a5\u53e3\u53d1\u9001IP\u6570\u636e\u5305\uff0c\u5c31\u597d\u50cf\u5bf9\u4e00\u4e2a\u771f\u5b9e\u7684\u7f51\u5361\u8fdb\u884c\u64cd\u4f5c\u4e00\u6837\u3002\u9664\u4e86\u5e94\u7528\u7a0b\u5e8f\u4ee5\u5916\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4e5f\u4f1a\u6839\u636eTCP\/IP\u534f\u8bae\u6808\u7684\u5904\u7406\u5411Tun\/Tap\u63a5\u53e3\u53d1\u9001IP\u6570\u636e\u5305\u6216\u8005\u4ee5\u592a\u7f51\u6570\u636e\u5305\uff0c\u4f8b\u5982ARP\u6216\u8005ICMP\u6570\u636e\u5305\u3002Tun\/Tap\u9a71\u52a8\u7a0b\u5e8f\u4f1a\u5c06Tun\/Tap\u63a5\u53e3\u6536\u5230\u7684\u6570\u636e\u5305\u539f\u6837\u5199\u5165\u5230\/dev\/net\/tun\u5b57\u7b26\u8bbe\u5907\u4e0a\uff0c\u5904\u7406Tun\/Tap\u6570\u636e\u7684\u5e94\u7528\u7a0b\u5e8f\u5982V**\u7a0b\u5e8f\u53ef\u4ee5\u4ece\u8be5\u8bbe\u5907\u4e0a\u8bfb\u53d6\u5230\u6570\u636e\u5305\uff0c\u4ee5\u8fdb\u884c\u76f8\u5e94\u5904\u7406\u3002<\/p>\n \u5e94\u7528\u7a0b\u5e8f\u4e5f\u53ef\u4ee5\u901a\u8fc7\/dev\/net\/tun\u5b57\u7b26\u8bbe\u5907\u5199\u5165\u6570\u636e\u5305\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u8be5\u5b57\u7b26\u8bbe\u5907\u4e0a\u5199\u5165\u7684\u6570\u636e\u5305\u4f1a\u88ab\u53d1\u9001\u5230Tun\/Tap\u865a\u62df\u63a5\u53e3\u4e0a\uff0c\u8fdb\u5165\u64cd\u4f5c\u7cfb\u7edf\u7684TCP\/IP\u534f\u8bae\u6808\u8fdb\u884c\u76f8\u5e94\u5904\u7406\uff0c\u5c31\u50cf\u4ece\u7269\u7406\u7f51\u5361\u8fdb\u5165\u64cd\u4f5c\u7cfb\u7edf\u7684\u6570\u636e\u4e00\u6837\u3002<\/p>\n Tun\u865a\u62df\u8bbe\u5907\u548c\u7269\u7406\u7f51\u5361\u7684\u533a\u522b\u662fTun\u865a\u62df\u8bbe\u5907\u662fIP\u5c42\u8bbe\u5907\uff0c\u4ece\/dev\/net\/tun\u5b57\u7b26\u8bbe\u5907\u4e0a\u8bfb\u53d6\u7684\u662fIP\u6570\u636e\u5305\uff0c\u5199\u5165\u7684\u4e5f\u53ea\u80fd\u662fIP\u6570\u636e\u5305\uff0c\u56e0\u6b64\u4e0d\u80fd\u8fdb\u884c\u4e8c\u5c42\u64cd\u4f5c\uff0c\u5982\u53d1\u9001ARP\u8bf7\u6c42\u548c\u4ee5\u592a\u7f51\u5e7f\u64ad\u3002\u4e0e\u4e4b\u76f8\u5bf9\u7684\u662f\uff0cTap\u865a\u62df\u8bbe\u5907\u662f\u4ee5\u592a\u7f51\u8bbe\u5907\uff0c\u5904\u7406\u7684\u662f\u4e8c\u5c42\u4ee5\u592a\u7f51\u6570\u636e\u5e27\uff0c\u4ece\/dev\/net\/tun\u5b57\u7b26\u8bbe\u5907\u4e0a\u8bfb\u53d6\u7684\u662f\u4ee5\u592a\u7f51\u6570\u636e\u5e27\uff0c\u5199\u5165\u7684\u4e5f\u53ea\u80fd\u662f\u4ee5\u592a\u7f51\u6570\u636e\u5e27\u3002\u4ece\u8fd9\u70b9\u6765\u770b\uff0cTap\u865a\u62df\u8bbe\u5907\u548c\u771f\u5b9e\u7684\u7269\u7406\u7f51\u5361\u7684\u80fd\u529b\u66f4\u63a5\u8fd1\u3002 \u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u4ece\/dev\/net\/tun\u5b57\u7b26\u8bbe\u5907\u4e2d\u8bfb\u53d6\u6216\u8005\u5199\u5165\u6570\u636e\u770b\u4e0a\u53bb\u5e76\u6ca1\u6709\u592a\u5927\u7528\u5904\uff0c\u4f46\u901a\u8fc7\u5c06Tun\/Tap\u7ed3\u5408\u7269\u7406\u7f51\u7edc\u8bbe\u5907\u4f7f\u7528,\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u70b9\u5bf9\u70b9\u7684\u96a7\u9053\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5de6\u8fb9\u4e3b\u673a\u4e0a\u5e94\u7528\u7a0b\u5e8f\u53d1\u9001\u5230Tun\u865a\u62df\u8bbe\u5907\u4e0a\u7684IP\u6570\u636e\u5305\u88abV**\u7a0b\u5e8f\u901a\u8fc7\u5b57\u7b26\u8bbe\u5907\u63a5\u6536\uff0c\u7136\u540e\u518d\u901a\u8fc7\u4e00\u4e2aTCP\u6216\u8005UDP\u96a7\u9053\u53d1\u9001\u5230\u53f3\u7aef\u7684V**\u670d\u52a1\u5668\u4e0a\uff0cV**\u670d\u52a1\u5668\u5c06\u96a7\u9053\u8d1f\u8f7d\u4e2d\u7684\u539f\u59cbIP\u6570\u636e\u5305\u5199\u5165\u5b57\u7b26\u8bbe\u5907\uff0c\u8fd9\u4e9bIP\u5305\u5c31\u4f1a\u51fa\u73b0\u5728\u53f3\u4fa7\u7684Tun\u865a\u62df\u8bbe\u5907\u4e0a\uff0c\u6700\u540e\u901a\u8fc7\u64cd\u4f5c\u7cfb\u7edf\u534f\u8bae\u6808\u548csocket\u63a5\u53e3\u53d1\u9001\u5230\u53f3\u4fa7\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0a\u3002 \u4e0a\u56fe\u4e2d\u7684\u96a7\u9053\u4e5f\u53ef\u4ee5\u91c7\u7528Tap\u865a\u62df\u8bbe\u5907\u5b9e\u73b0\u3002\u4f7f\u7528Tap\u7684\u8bdd\uff0c\u96a7\u9053\u7684\u8d1f\u8f7d\u5c06\u662f\u4ee5\u592a\u6570\u636e\u5e27\u800c\u4e0d\u662fIP\u6570\u636e\u5305\uff0c\u800c\u4e14\u8fd8\u4f1a\u4f20\u9012ARP\u7b49\u5e7f\u64ad\u6570\u636e\u5305\u3002<\/p>\n <\/p>\n \u4f7f\u7528Tun\/Tap\u96a7\u9053\u7ed5\u8fc7\u9632\u706b\u5899<\/strong><\/div>\n \u7ed3\u5408\u8def\u7531\u89c4\u5219\u548cIPTables\u89c4\u5219\uff0c\u53ef\u4ee5\u5c06V**\u670d\u52a1\u5668\u7aef\u7684\u4e3b\u673a\u4f5c\u4e3a\u8fde\u63a5\u5916\u90e8\u7f51\u7edc\u7684\u7f51\u5173\uff0c\u4ee5\u7ed5\u8fc7\u9632\u706b\u5899\u5bf9\u5ba2\u6237\u7aef\u7684\u4e00\u4e9b\u5916\u90e8\u7f51\u7edc\u8bbf\u95ee\u9650\u5236\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u9632\u706b\u5899\u89c4\u5219\u5141\u8bb8\u5ba2\u6237\u7aef\u8bbf\u95ee\u4e3b\u673aIP2\uff0c\u800c\u7981\u6b62\u8bbf\u95ee\u5176\u4ed6Internet\u4e0a\u7684\u8282\u70b9\u3002\u901a\u8fc7\u91c7\u7528Tun\u96a7\u9053\uff0c\u4ece\u9632\u706b\u5899\u89d2\u5ea6\u53ea\u80fd\u770b\u5230\u88ab\u5c01\u88c5\u540e\u7684\u6570\u636e\u5305\uff0c\u56e0\u6b64\u9632\u706b\u5899\u8ba4\u4e3a\u5ba2\u6237\u7aef\u53ea\u662f\u5728\u8bbf\u95eeIP2\uff0c\u4f1a\u5bf9\u6570\u636e\u8fdb\u884c\u653e\u884c\u3002\u800cV**\u670d\u52a1\u7aef\u5728\u89e3\u5305\u5f97\u5230\u771f\u5b9e\u7684\u8bbf\u95ee\u76ee\u7684\u540e\uff0c\u4f1a\u901a\u8fc7\u8def\u7531\u89c4\u5219\u548cIPTables\u89c4\u5219\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u771f\u6b63\u7684\u8bbf\u95ee\u76ee\u7684\u5730\u4e0a\uff0c\u7136\u540e\u518d\u5c06\u771f\u5b9e\u76ee\u7684\u5730\u7684\u54cd\u5e94IP\u6570\u636e\u5305\u5c01\u88c5\u8fdb\u96a7\u9053\u540e\u539f\u8def\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\uff0c\u4ece\u800c\u8fbe\u5230\u7ed5\u8fc7\u9632\u706b\u5899\u9650\u5236\u7684\u76ee\u7684\u3002<\/p>\n <\/p>\n \u4f7f\u7528Tap\u96a7\u9053\u6865\u63a5\u4e24\u4e2a\u8fdc\u7a0b\u7ad9\u70b9<\/strong><\/div>\n \u5982\u4e0b\u56fe\u6240\u793a\uff0c\u53ef\u4ee5\u4f7f\u7528tap\u5efa\u7acb\u4e8c\u5c42\u96a7\u9053\u5c06\u4e24\u4e2a\u8fdc\u7a0b\u7ad9\u70b9\u6865\u63a5\u8d77\u6765\uff0c\u7ec4\u6210\u4e00\u4e2a\u5c40\u57df\u7f51\u3002\u5bf9\u4e8e\u4e24\u8fb9\u7ad9\u70b9\u4e2d\u7684\u4e3b\u673a\u6765\u8bf4\uff0c\u8bbf\u95ee\u5bf9\u65b9\u7ad9\u70b9\u7684\u4e3b\u673a\u548c\u672c\u5730\u7ad9\u70b9\u7684\u4e3b\u673a\u7684\u65b9\u5f0f\u6ca1\u6709\u533a\u522b\uff0c\u90fd\u5904\u4e8e\u4e00\u4e2a\u5c40\u57df\u7f51192.168.0.0\/24\u4e2d\u3002 <\/p>\n \u5047\u8bbe192.168.0.5\u53d1\u51fa\u4e86\u4e00\u4e2a\u5bf9192.168.0.3\u7684ARP\u8bf7\u6c42\uff0c\u8be5ARP\u8bf7\u6c42\u5728\u7f51\u7edc\u4e2d\u7ecf\u8fc7\u7684\u8def\u5f84\u5982\u4e0b\uff1a<\/p>\n 192.168.0.5\u53d1\u51faARP\u8bf7\u6c42\uff0c\u8be2\u95ee192.168.0.3\u7684MAC\u5730\u5740\u3002 \u4ece\u7ad9\u70b9\u4e3b\u673a\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u4e0a\u9762\u56fe\u4e2d\u4e24\u4e2aV**\u4e3b\u673a\u4e4b\u95f4\u7684\u8fdc\u7a0b\u8fde\u63a5\u53ef\u4ee5\u770b\u4f5c\u4e00\u6761\u865a\u62df\u7684\u7f51\u7ebf\uff0c\u8fd9\u6761\u7f51\u7ebf\u5c06\u4e24\u4e2aLinux Bridge\u8fde\u63a5\u8d77\u6765\u3002\u8fd9\u4e24\u4e2aLinux Bridge\u548c\u4e24\u4e2a\u4ee5\u592a\u7f51\u4ea4\u6362\u673a\u4e00\u8d77\u5c06\u5de6\u53f3\u4e24\u4e2a\u7ad9\u70b9\u7684\u4e3b\u673a\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u5f62\u6210\u4e86\u4e00\u4e2a\u5c40\u57df\u7f51\u3002<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" TAP\u7b49\u540c\u4e8e\u4e00\u4e2a\u4ee5\u592a\u7f51\u8bbe\u5907\uff0c\u5b83\u64cd\u4f5c\u7b2c\u4e8c\u5c42\u6570\u636e\u5305\u5982\u4ee5\u592a\u7f51\u6570\u636e\u5e27\u3002TUN\u6a21\u62df\u4e86\u7f51\u7edc\u5c42\u8bbe\u5907\uff0c\u64cd\u4f5c\u7b2c\u4e09\u5c42\u6570\u636e\u5305\u6bd4\u5982IP […]<\/p>\n","protected":false},"author":310,"featured_media":261636,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-261626","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\/261626","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\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=261626"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/261626\/revisions"}],"predecessor-version":[{"id":261762,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/261626\/revisions\/261762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/261636"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=261626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=261626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=261626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} |