{"id":34,"date":"2019-07-22T13:52:02","date_gmt":"2019-07-22T05:52:02","guid":{"rendered":"http:\/\/blog.ohmmx.com\/?p=34"},"modified":"2021-12-28T10:32:07","modified_gmt":"2021-12-28T02:32:07","slug":"%e7%ae%80%e5%8d%95%e8%ae%be%e7%bd%ae%e9%98%b2%e7%81%ab%e5%a2%99","status":"publish","type":"post","link":"http:\/\/blog.ohmmx.com\/?p=34","title":{"rendered":"\u7b80\u5355\u8bbe\u7f6e\u9632\u706b\u5899"},"content":{"rendered":"\n<p>\u5f00\u59cb\u4e4b\u524d\u5148\u5173\u95edSELINUX\u3002<\/p>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2aLinux\u4e0b\u7684\u8bbf\u95ee\u63a7\u5236\u7cfb\u7edf\uff0c\u4e3b\u8981\u8fdb\u884c\u5b89\u5168\u7b56\u7565\u548c\u6743\u9650\u63a7\u5236\u7684\u7ba1\u7406\uff0c\u5bf9\u5f88\u591a\u6d89\u53ca\u76ee\u5f55\u548c\u6587\u4ef6\u7684\u64cd\u4f5c\u90fd\u4f1a\u4ea7\u751f\u5f71\u54cd\uff0c\u4e2a\u4eba\u7528\u6237\u5efa\u8bae\u5173\u95ed\uff0c\u5982\u6709\u5174\u8da3\u4e86\u89e3\u53ef\u4ee5\u5355\u72ec\u8fdb\u884c\u5b66\u4e60\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/selinux\/config<\/code><\/pre>\n\n\n\n<p>\u5c06 SELINUX=enforcing \u4fee\u6539\u4e3a SELINUX=disabled<\/p>\n\n\n\n<p>\u7136\u540e\u91cd\u542f\u7cfb\u7edf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reboot<\/code><\/pre>\n\n\n\n<p>\u7f51\u7edc\u9632\u706b\u5899FirewallD\u7b80\u5355\u8bb2\u89e3\u3002<\/p>\n\n\n\n<p>FirewallD\u5c31\u662fLinux\u4e0b\u7684\u9632\u706b\u5899\uff0c\u8fd9\u91cc\u4ecb\u7ecd\u4e00\u4e9b\u5e38\u7528\u7684\u547d\u4ee4\u6765\u5e94\u5bf9\u540e\u9762\u642d\u5efaWEB\u670d\u52a1\u5668\u7684\u9700\u8981\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u662f\u9632\u706b\u5899\u7684\u5f00\u5173\u547d\u4ee4\uff0c\u5982\u679c\u4e0d\u60f3\u8981\u9632\u706b\u5899\u53ef\u4ee5\u76f4\u63a5\u5173\u95ed\u5e76\u53d6\u6d88\u5f00\u673a\u542f\u52a8\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u542f\u52a8FirewallD\nsystemctl start firewalld\n# \u5173\u95ed FirewallD\nsystemctl start firewalld\n# \u8bbe\u7f6e\u5f00\u673a\u542f\u52a8\uff08\u5f53\u524d\u5982\u679c\u6ca1\u542f\u52a8\u5e76\u4e0d\u4f1a\u542f\u52a8\uff09\nsystemctl enable firewalld\n# \u53d6\u6d88\u5f00\u673a\u542f\u52a8\uff08\u5e76\u4e0d\u4f1a\u5173\u95ed\u542f\u52a8\u4e2d\u7684\u9632\u706b\u5899\uff09\nsystemctl disable firewalld\n# \u67e5\u770b\u9632\u706b\u5899\u8fd0\u884c\u72b6\u6001\nsystemctl status firewalld\n# \u67e5\u770b\u6240\u6709\u9632\u706b\u5899\u89c4\u5219\nfirewall-cmd --list-all\n# \u91cd\u65b0\u52a0\u8f7d\u9632\u706b\u5899\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n<p>\u670d\u52a1\u7684\u7ba1\u7406\uff0cFirewallD\u7684\u670d\u52a1\u914d\u7f6e\u6587\u4ef6\u5728\/usr\/lib\/firewalld\/services\/\u4e0b\uff0c\u53ef\u4ee5\u7406\u89e3\u6210\u4e00\u4e2a\u6279\u91cf\u5305\uff0c\u5982\u679c\u9632\u706b\u5899\u5141\u8bb8\u67d0\u4e2aservice\uff0c\u90a3\u4e48\u8be5service\u4e0b\u7684\u6240\u6709\u89c4\u5219\u5c06\u5168\u88ab\u5141\u8bb8\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u9700\u8981\u4fee\u6539\u7cfb\u7edf\u670d\u52a1\u7684\u9ed8\u8ba4\u7aef\u53e3\uff0c\u8981\u5c06\u5bf9\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\u590d\u5236\/etc\/firewalld\/services\u76ee\u5f55\u5e76\u8fdb\u884c\u8c03\u6574\u3002\u5982\u679c\u76f4\u63a5\u4fee\u6539\uff0c\u5728\u7cfb\u7edf\u5347\u7ea7\u65f6\u4f1a\u91cd\u7f6e\u4e3a\u9ed8\u8ba4\u914d\u7f6e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u67e5\u770b\u6240\u6709\u53ef\u4ee5\u8bbe\u7f6e\u7684\u670d\u52a1\nfirewall-cmd --get-services\n# \u67e5\u770b\u5f53\u524d\u5141\u8bb8\u7684\u670d\u52a1\nfirewall-cmd --list-services\n# \u67e5\u8be2\u4e00\u4e2a\u670d\u52a1\u7684\u72b6\u6001\nfirewall-cmd --query-service http\n# \u5141\u8bb8\u4e00\u4e2a\u670d\u52a1\nfirewall-cmd --add-service=http\n# \u7981\u6b62\u4e00\u4e2a\u670d\u52a1\nfirewall-cmd --remove-service=http\n# \u5141\u8bb8\u4e00\u4e2a\u670d\u52a1\u591a\u5c11\u79d2\nfirewall-cmd --add-service=http --timeout=60<\/code><\/pre>\n\n\n\n<p class=\"has-text-color\" style=\"color:#ff0000\">\u6ce8\u610f\uff1a\u8fd9\u4e9b\u8bbe\u7f6e\u5728\u91cd\u65b0\u52a0\u8f7d\u9632\u706b\u5899\u6216\u8005\u91cd\u542f\u7cfb\u7edf\u540e\u5c06\u4f1a\u5931\u6548\uff0c\u5982\u679c\u60f3\u8981\u8ba9\u8bbe\u7f6e\u6c38\u4e45\u751f\u6548\uff0c\u9700\u8981\u6dfb\u52a0&#8211;permanent\u53c2\u6570<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>firewall-cmd --permanent --add-service=http<\/code><\/pre>\n\n\n\n<p>\u4f46\u662f\u8fd9\u6837\u8bbe\u7f6e\u5e76\u4e0d\u4f1a\u7acb\u5373\u751f\u6548\uff0c\u9700\u8981\u91cd\u65b0\u52a0\u8f7d\u9632\u706b\u5899\u4f7f\u5176\u751f\u6548\u3002\u540c\u6837\uff0c\u5220\u9664\u670d\u52a1\u5305\u62ec\u540e\u9762\u7684\u7aef\u53e3\u7ba1\u7406\u8981\u6c38\u4e45\u751f\u6548\u90fd\u8981\u6dfb\u52a0\u8be5\u53c2\u6570\u3002<\/p>\n\n\n\n<p>\u7aef\u53e3\u7684\u7ba1\u7406\uff0c\u5982\u679c\u6709\u4e00\u4e9b\u8f6f\u4ef6\u4e0d\u5728\u5e38\u7528\u670d\u52a1\u5217\u8868\u91cc\uff0c\u6216\u8005\u628a\u7cfb\u7edf\u670d\u52a1\u7684\u9ed8\u8ba4\u7aef\u53e3\u66f4\u6539\u4e86\uff0c\u53ef\u4ee5\u76f4\u63a5\u6dfb\u52a0\u4e00\u4e2a\u5141\u8bb8\u8bbf\u95ee\u7684\u7aef\u53e3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u67e5\u770b\u5f53\u524d\u5141\u8bb8\u7684\u7aef\u53e3\nfirewall-cmd --list-ports\n# \u6dfb\u52a0\u4e00\u4e2a\u5141\u8bb8\u7684\u7aef\u53e3\nfirewall-cmd --add-port=8080\/tcp\n# \u5220\u9664\u4e00\u4e2a\u5141\u8bb8\u7684\u7aef\u53e3\nfirewall-cmd --remove-port=8080\/tcp\n# \u6dfb\u52a0\u4e00\u4e2a\u5141\u8bb8\u7684\u7aef\u53e3\u591a\u5c11\u79d2\nfirewall-cmd --add-port=8080\/tcp --timeout=60<\/code><\/pre>\n\n\n\n<p>\u540c\u6837\uff0c\u8981\u4f7f\u5176\u6c38\u4e45\u751f\u6548\u9700\u8981\u6dfb\u52a0\u53c2\u6570permanent\uff0c\u540e\u9762\u5c06\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n\n\n\n<p>\u9632\u706b\u5899\u8fd8\u6709\u4e00\u4e2a\u5c0f\u529f\u80fd\uff0c\u53ef\u4ee5\u8fdb\u884c\u7aef\u53e3\u8f6c\u53d1\uff0cLinux\u4e0d\u5141\u8bb8root\u4ee5\u5916\u7684\u7528\u6237\u4f7f\u75281024\u4ee5\u4e0b\u7684\u7aef\u53e3\uff0c\u6211\u4eec\u4e3e\u4f8b\u8bbe\u7f6e\u4e00\u4e2a1024\u4ee5\u4e0a\u7684\u7aef\u53e3\u8f6c\u53d1\u523080\u7aef\u53e3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u8bbf\u95ee\u8be5\u673a\u768480\u7aef\u53e3\u5c06\u88ab\u8f6c\u53d1\u52308080\u7aef\u53e3\uff0c\u8fd9\u91cc\u8f6c\u53d1\u7684\u76ee\u6807\u5730\u5740\u9700\u8981\u6dfb\u52a0\u9632\u706b\u5899\u5141\u8bb8\uff0c\u4e5f\u5c31\u662f\u8981\u5141\u8bb88080\u7aef\u53e3\u8bbf\u95ee\uff0c\u800c\u6307\u5411\u7aef\u53e3\u4e0d\u7528\u5728\u9632\u706b\u5899\u91cc\u8bbe\u7f6e\u5141\u8bb8\uff0c\u8fd9\u91cc\u662f80\u7aef\u53e3\u3002<\/p>\n\n\n\n<p>\u9632\u706b\u5899\u7684\u8bbe\u7f6e\u5c31\u7b80\u5355\u4ecb\u7ecd\u5230\u8fd9\u91cc\uff0c\u5982\u9700\u8981\u66f4\u52a0\u8be6\u7ec6\u7684\u5b66\u4e60\u8bf7\u67e5\u8be2\u4e13\u4e1a\u8d44\u6599\uff0c\u5176\u4e2d\u6bd4\u8f83\u91cd\u8981\u7684\u662f\u9632\u706b\u5899\u7684filter\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f00\u59cb\u4e4b\u524d\u5148\u5173\u95edSELINUX\u3002 \u8fd9\u662f\u4e00\u4e2aLinux\u4e0b\u7684\u8bbf\u95ee\u63a7\u5236\u7cfb\u7edf\uff0c\u4e3b\u8981\u8fdb\u884c\u5b89\u5168 &hellip; <a href=\"http:\/\/blog.ohmmx.com\/?p=34\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[12,11],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-server","tag-firewalld","tag-11"],"_links":{"self":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=34"}],"version-history":[{"count":3,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":125,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions\/125"}],"wp:attachment":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}