{"id":45,"date":"2023-08-29T01:20:00","date_gmt":"2023-08-28T17:20:00","guid":{"rendered":"https:\/\/flymlc.com\/?p=45"},"modified":"2024-07-05T01:24:55","modified_gmt":"2024-07-04T17:24:55","slug":"%e8%ae%b0ufw%e5%af%b9docker%e5%bc%80%e6%94%be%e7%ab%af%e5%8f%a3%e6%97%a0%e6%95%88%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/flymlc.com\/index.php\/2023\/08\/29\/%e8%ae%b0ufw%e5%af%b9docker%e5%bc%80%e6%94%be%e7%ab%af%e5%8f%a3%e6%97%a0%e6%95%88%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88\/","title":{"rendered":"\u8bb0ufw\u5bf9docker\u5f00\u653e\u7aef\u53e3\u65e0\u6548\u7684\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5728\u4f7f\u7528docker\u65f6,\u53d1\u73b0\u4e86docker\u5f00\u542f\u7684\u7aef\u53e3\u5c45\u7136\u4e0d\u53d7ufw\u9632\u706b\u5899\u7684\u9650\u5236,\u5c31\u8fd9\u4e48\u7ed5\u8fc7\u6211\u7684\u9632\u706b\u5899\u8ba9\u6211\u975e\u5e38\u6ef4\u6ca1\u9762\u5b50\u554a...\u5fc5\u987b\u5f97\u6cbb!<\/p>\n\n\n\n<p>\u9042\u53bb\u7f51\u4e0a\u67e5\u8be2\u539f\u56e0\u4e0e\u89e3\u51b3\u65b9\u6848,\u53d1\u73b0\u53d1\u751f\u539f\u56e0\u662fdocker\u4f1a\u81ea\u52a8\u4fee\u6539iptables\u6253\u5f00\u76f8\u5e94\u9632\u706b\u5899\u7aef\u53e3,\u4f7f\u5f97ufw\u5b8c\u5168\u65e0\u6548,\u8981\u662f\u8fd9\u6837\u7684\u8bdd\u6211nginx\u53cd\u4ee3\u8fd8\u6709\u4ec0\u4e48\u610f\u4e49?(<s>\u5410\u69fd:\u54ea\u6015ufw\u65e0\u6548nginx\u610f\u4e49\u4e5f\u5927\u7740\u5427...<\/s>)\u5fc5\u987b\u5f97\u6cbb\u6cbbdocker!<\/p>\n\n\n\n<p>\u4e0d\u8fc7\u7f51\u4e0a\u7684\u6559\u7a0b\u5927\u591a\u662f\u7981\u6b62docker\u66f4\u65b0iptables,\u8fd9\u6837\u4f1a\u7559\u4e0b\u7684\u95ee\u9898\u4e0d\u7528\u6211\u89e3\u91ca\u4e86\u5427~<\/p>\n\n\n\n<p>\u5bfb\u627e\u7247\u523b,\u53bb\u6280\u672f\u8bba\u575b\u4e0a\u5bfb\u5230\u4e86\u4e2a\u57fa\u4e8eufw\u7684\u4f4e\u4fb5\u5165\u6027\u89e3\u51b3\u65b9\u6848~<\/p>\n\n\n\n<p>\u9996\u5148\u4fee\u6539ufw\u914d\u7f6e\u6587\u4ef6:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/ufw\/after.rules<\/code><\/pre>\n\n\n\n<p>\u5728\u672b\u5c3e\u52a0\u4e0a:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># BEGIN UFW AND DOCKER\n*filter\n:ufw-user-forward - &#91;0:0]\n:DOCKER-USER - &#91;0:0]\n-A DOCKER-USER -j RETURN -s 10.0.0.0\/8\n-A DOCKER-USER -j RETURN -s 172.16.0.0\/12\n-A DOCKER-USER -j RETURN -s 192.168.0.0\/16\n\n-A DOCKER-USER -j ufw-user-forward\n\n-A DOCKER-USER -j DROP -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -d 192.168.0.0\/16\n-A DOCKER-USER -j DROP -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -d 10.0.0.0\/8\n-A DOCKER-USER -j DROP -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -d 172.16.0.0\/12\n-A DOCKER-USER -j DROP -p udp -m udp --dport 0:32767 -d 192.168.0.0\/16\n-A DOCKER-USER -j DROP -p udp -m udp --dport 0:32767 -d 10.0.0.0\/8\n-A DOCKER-USER -j DROP -p udp -m udp --dport 0:32767 -d 172.16.0.0\/12\n\n-A DOCKER-USER -j RETURN\nCOMMIT\n# END UFW AND DOCKER<\/code><\/pre>\n\n\n\n<p>\u4fdd\u5b58\u5e76\u91cd\u542fufw\u5373\u53ef~<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart ufw<\/code><\/pre>\n\n\n\n<p>\u786e\u5b9e\u5341\u5206\u7b80\u5355,\u4e0d\u8fc7\u8fd9\u79cd\u4f4e\u4fb5\u5165\u6027\u7684\u65b9\u6848\u6bd4\u8f83\u5c11\u89c1,\u800c\u8fd9\u4e2a\u6f0f\u6d1e\u8fd8\u662f\u8981\u5904\u7406\u7684~\u6240\u4ee5\u8bb0\u5f55\u4e00\u4e0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u4f7f\u7528docker\u65f6,\u53d1\u73b0\u4e86docker\u5f00\u542f\u7684\u7aef\u53e3\u5c45\u7136\u4e0d\u53d7ufw\u9632\u706b\u5899\u7684\u9650\u5236,\u5c31\u8fd9\u4e48\u7ed5\u8fc7\u6211\u7684\u9632\u706b\u5899\u8ba9\u6211\u975e\u5e38\u6ef4\u6ca1\u9762\u5b50\u554a&#8230;\u5fc5\u987b &#8230;","protected":false},"author":1,"featured_media":47,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":1,"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/posts\/45\/revisions\/46"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/media\/47"}],"wp:attachment":[{"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flymlc.com\/index.php\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}