{"id":11905,"date":"2023-08-17T16:29:24","date_gmt":"2023-08-17T08:29:24","guid":{"rendered":"http:\/\/92it.top\/?p=11905"},"modified":"2023-08-17T16:29:24","modified_gmt":"2023-08-17T08:29:24","slug":"linux%e7%ab%af%e5%8f%a3%e6%98%a0%e5%b0%84%e8%bd%ac%e5%8f%91%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=11905","title":{"rendered":"Linux\u7aef\u53e3\u6620\u5c04\u8f6c\u53d1\u7684\u65b9\u6cd5"},"content":{"rendered":"\n<p><strong>\u524d\u8a00<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5f53\u6211\u4eec\u5728\u5bf9\u63a5\u7b2c\u4e09\u65b9\u7684\u65f6\u5019\uff0c\u514d\u4e0d\u4e86\u4f1a\u9047\u5230\u767d\u540d\u5355\u9650\u5236\u95ee\u9898\uff0c\u5bfc\u81f4\u6211\u4eec\u672c\u5730\u5f00\u53d1\u73af\u5883\u53d7\u9650\uff0c\u4e0d\u80fd\u8c03\u7528\u63a5\u53e3\u3002\u96be\u4ee5\u5b8c\u6210\u6574\u4e2a\u4e1a\u52a1\u6d41\u7a0b\u3002<\/p>\n\n\n\n<p><strong>\u5206\u6790\u5982\u4e0b\u573a\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u6bd4\u5982\u7b2c\u4e09\u65b9\u6709\u53f0\u673a\u5668 IP \u4e3a 1.1.1.1&nbsp; \u7aef\u53e38080<\/p>\n\n\n\n<p>\u6b63\u5f0f\u73af\u5883\u4e3a1.1.1.1\uff1a8080\/pro\/api<\/p>\n\n\n\n<p>\u6d4b\u8bd5\u73af\u5883\u4e3a1.1.1.1\uff1a8080\/test\/api<\/p>\n\n\n\n<p>\u4f46\u662f\u7b2c\u4e09\u65b9\u7684\u673a\u5668\u4e0d\u5141\u8bb8\u4efb\u4f55IP\u90fd\u53ef\u4ee5\u8c03\u7528\uff0c\u4ed6\u4eec\u53ea\u5141\u8bb8\u4f60\u65b9\u4e00\u53f0\u673a\u5668\u52a0\u5165\u767d\u540d\u5355<\/p>\n\n\n\n<p>\u6bd4\u5982\u4f60\u7ebf\u4e0a\u7684\u4e00\u53f0\u673a\u5668IP\u662f2.2.2.2\u5df2\u7ecf\u52a0\u5165\u767d\u540d\u5355\uff0c\u8fd9\u6ca1\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u4f60\u8981\u505a\u5f00\u53d1 \u8981\u8c03\u7528\u4ed6\u4eec\u6d4b\u8bd5\u73af\u5883\u7684API\uff0c\u5374\u53d1\u73b0\u8c03\u7528\u4e0d\u4e86\uff0c\u800c\u4e14\u4f60\u603b\u4e0d\u80fd\u57282.2.2.2\u4e0a\u9762\u5199\u4ee3\u7801\u8c03\u8bd5\u5427\u3002<\/p>\n\n\n\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u8df3\u677f\u670d\u52a1<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u65e2\u7136\u4e0d\u80fd\u76f4\u63a5\u8c03\u75281.1.1.1 \u90a3\u4e48\u5b8c\u5168\u8ba92.2.2.2\u5199\u4e2a\u670d\u52a1\uff0c\u4f5c\u4e3a\u8df3\u677f\uff0c\u4e5f\u5c31\u662f\u628a\u6211\u4eec\u7684\u8bf7\u6c42\u7ed92.2.2.2,\u7136\u540e2.2.2.2\u518d\u539f\u5c01\u4e0d\u52a8\u4f20\u7ed91.1.1.1<\/p>\n\n\n\n<p><strong>Nginx\u8f6c\u53d1<\/strong><\/p>\n\n\n\n<p>\u8fd9\u4e2a\u4f1a\u6bd4\u8df3\u677f\u670d\u52a1\u7b80\u5355\u591a\u4e86\u3002\u53ea\u89812.2.2.2 \u5f00\u542fnginx<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">listen    8080;\nlocation \/test\/api\/{\n  proxy_pass 1.1.1.1:8080;\n}\n<\/pre>\n\n\n\n<p><strong>\u7aef\u53e3\u6620\u5c04<\/strong><\/p>\n\n\n\n<p>\u65e0\u8bba\u662f\u8df3\u677f\u670d\u52a1\u8fd8\u662fnginx\u8f6c\u53d1 \u6211\u4eec\u8981\u505a\u7684\u4e8b\u60c5\u5c31\u66f4\u591a\u4e86\u3002\u6240\u4ee5\u6211\u4eec\u8981\u60f3\u5230\u53e6\u4e00\u79cd\u601d\u8def\u3002\u5c31\u662f2.2.2.2\u8fd9\u53f0\u673a\u5668\u80fd\u4e0d\u80fd\u5e2e\u6211\u8f6c\u53d1\uff0c\u53ea\u662f\u4f5c\u4e3a\u4e00\u4e2a\u4e2d\u95f4\u8005\u3002\u5c31\u662f\u6211\u8bf7\u6c42\u4e862.2.2.2:8080 \u5b9e\u9645\u4e0a\u8bf7\u6c42\u5230\u4e86\u662f1.1.1.1:8080\u3002\u5373\u4e3a\u7aef\u53e3\u6620\u5c04\u3002\u4e0a\u9762\u4e24\u79cd\u65b9\u6848\u4ec5\u4ec5\u662f\u7528\u5728http\u3002\u90a3\u5982\u679c\u662f\u5176\u4ed6\u534f\u8bae\u5462 \u6bd4\u5982\u8bf4sftp(ssh) ftp\u3002\u4e5f\u4ec5\u4ec5\u53ea\u6709\u6b64\u65b9\u6848\u80fd\u80dc\u4efb\u3002<\/p>\n\n\n\n<p>Linux\u7aef\u53e3\u6620\u5c04\uff0c\u53c8\u79f0\u4e3a\u7aef\u53e3\u8f6c\u53d1\uff0c\u662f\u4e00\u79cd\u7f51\u7edc\u6280\u672f\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u53f0\u670d\u52a1\u5668\u7684IP\u5730\u5740\u4e0a\u7684\u865a\u62df\u4e3b\u673a\u6620\u5c04\u5230\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u6307\u5b9a\u7aef\u53e3\u3002\u8fd9\u6837\uff0c\u5ba2\u6237\u7aef\u53ef\u4ee5\u901a\u8fc7\u63d0\u4f9b\u7684IP\u5730\u5740\u76f4\u63a5\u8bbf\u95ee\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7684\u6307\u5b9a\u7aef\u53e3\uff0c\u800c\u65e0\u9700\u77e5\u9053\u76ee\u7684\u5730\u7684IP\u5730\u5740\u6216\u7aef\u53e3\u3002<\/p>\n\n\n\n<p>Linux\u7aef\u53e3\u6620\u5c04\u7684\u539f\u7406\u662f\u57fa\u4e8e\u201cIP\u8f6c\u53d1\u201d\uff0c\u5b83\u4f7f\u7528IP\u534f\u8bae\u4e2d\u7684\u6e90\u7aef\u53e3\u548c\u76ee\u6807\u7aef\u53e3\uff0c\u4e3b\u8981\u7528\u4e8e\u8fde\u63a5\u672c\u5730\u4e3b\u673a\u548c\u8fdc\u7a0b\u4e3b\u673a\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u8f93\u3002\u5f53\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u5230\u6307\u5b9aIP\u5730\u5740\uff0c\u6307\u5b9a\u7aef\u53e3\u65f6\uff0cLinux\u7aef\u53e3\u6620\u5c04\u4f1a\u4fee\u6539\u6e90\u7aef\u53e3\uff0c\u5c06\u5176\u6620\u5c04\u5230\u6307\u5b9a\u7684IP\u5730\u5740\u548c\u7aef\u53e3\uff0c\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u7aef\u63a5\u53d7\u5230\u6b64\u6570\u636e\u540e\u8fd4\u56de\u62a5\u6587\u3002<\/p>\n\n\n\n<ul><li>vi \/etc\/sysctl.conf\u5f00\u542f\u5141\u8bb8\u7aef\u53e3\u8f6c\u53d1\u3002net.ipv4.ip_forward =1(CentOS7\u5219\u662f\u5728 \/usr\/lib\/sysctl.d\/50-default.conf\u989d\u5916\u6dfb\u52a0)<\/li><li>iptables -t nat -A PREROUTING -p tcp -d 2.2.2.2 \u2013dport 8080 -j DNAT \u2013to-destination 1.1.1.1:8080 \u8f6c\u53d1\u8bf7\u6c42<\/li><li>iptables -t nat -A POSTROUTING -p tcp -s 1.1.1.1 \u2013sport 8080 -j SNAT \u2013to-source 2.2.2.2:8080 \u8f6c\u53d1\u63a5\u6536<\/li><\/ul>\n\n\n\n<p>2.2.2.2 8080 \u8f6c\u53d1\u52301.1.1.1\uff1a8080 (\u5176\u4ed6\u884c\u60c5\u767e\u5ea6\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u672c\u5730\u673a\u5668\u7aef\u53e3\u8f6c\u53d1)<\/p>\n\n\n\n<ul><li>service iptables save \u4fdd\u5b58\u8bbe\u7f6e<\/li><li>service iptables restart \u91cd\u542f\u9632\u706b\u5899<\/li><\/ul>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>linux\u7aef\u53e3\u6620\u5c04\u7684\u4f18\u70b9<\/p>\n\n\n\n<ul><li>1\u3001\u7b80\u5316\u7f51\u7edc\u7ed3\u6784\u3002\u7531\u4e8e\u7aef\u53e3\u6620\u5c04\u53ef\u4ee5\u4f7f\u7528\u672c\u5730IP\u5730\u5740\uff0c\u800c\u4e0d\u9700\u8981\u5c06\u6570\u636e\u4ece\u8fdc\u7a0b\u4e3b\u673a\u4e2d\u505a\u8def\u7531\uff0c\u8fd9\u6837\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u8fde\u63a5\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\uff0c\u4ece\u800c\u7b80\u5316\u7f51\u7edc\u7ed3\u6784\uff0c\u4f7f\u7f51\u7edc\u66f4\u7a33\u5b9a\uff1b<\/li><li>2\u3001\u52a0\u5f3a\u5b89\u5168\u3002\u4f7f\u7528\u7aef\u53e3\u6620\u5c04\u53ef\u4ee5\u66f4\u52a0\u6709\u6548\u5730\u4fdd\u62a4\u7f51\u7edc\u5b89\u5168\uff0c\u4ec5\u5141\u8bb8\u6620\u5c04\u7f51\u7edc\u4e2d\u5141\u8bb8\u7684\u7aef\u53e3\u901a\u4fe1\uff0c\u62d2\u7edd\u5176\u4ed6\u65e0\u5173\u7684\u7aef\u53e3\uff0c\u6709\u6548\u4fdd\u62a4\u670d\u52a1\u5668\u5b89\u5168\uff1b<\/li><li>3\u3001\u9690\u85cf\u7f51\u7edc\u670d\u52a1\u3002\u4f7f\u7528\u7aef\u53e3\u6620\u5c04\u53ef\u4ee5\u9690\u85cf\u7f51\u7edc\u670d\u52a1\u8ba1\u7b97\u673a\u7684IP\u5730\u5740\uff0c\u4ece\u800c\u51cf\u5c11\u5916\u90e8\u7aef\u53e3\u4fa6\u67e5\u7a83\u53d6\u4fe1\u606f\u7684\u98ce\u9669\u3002<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5f53\u6211\u4eec\u5728\u5bf9\u63a5\u7b2c\u4e09\u65b9\u7684\u65f6\u5019\uff0c\u514d\u4e0d\u4e86\u4f1a\u9047\u5230\u767d\u540d\u5355\u9650\u5236\u95ee\u9898\uff0c\u5bfc\u81f4\u6211\u4eec\u672c\u5730\u5f00\u53d1\u73af\u5883\u53d7\u9650\uff0c\u4e0d\u80fd\u8c03\u7528\u63a5\u53e3\u3002\u96be\u4ee5\u5b8c\u6210\u6574 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11905"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11905"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11905\/revisions"}],"predecessor-version":[{"id":11907,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11905\/revisions\/11907"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}