{"id":45194,"date":"2024-10-06T21:09:16","date_gmt":"2024-10-06T13:09:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/45194\/"},"modified":"2024-10-06T21:09:16","modified_gmt":"2024-10-06T13:09:16","slug":"%e8%a7%a3%e6%b1%ba-rhel-7-centos-7-fedora-%e5%87%ba%e7%8f%be-unit-iptables-service-failed-to-load","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/45194\/","title":{"rendered":"\u89e3\u6c7a RHEL 7\/CentOS 7\/Fedora \u51fa\u73fe Unit iptables.service failed to load"},"content":{"rendered":"<h1 id=\"%e8%a7%a3%e6%b1%ba-rhel-7-centos-7-fedora-%e5%87%ba%e7%8f%be-unit-iptables-service-failed-to-load-LarCOMQSlB\">\u89e3\u6c7a RHEL 7\/CentOS 7\/Fedora \u51fa\u73fe Unit iptables.service failed to load<\/h1>\n<p>\u5728\u4f7f\u7528 RHEL 7\u3001CentOS 7 \u6216 Fedora \u7cfb\u7d71\u6642\uff0c\u60a8\u53ef\u80fd\u6703\u9047\u5230\u4e00\u500b\u5e38\u898b\u7684\u554f\u984c\uff1a\u7576\u60a8\u5617\u8a66\u555f\u52d5\u6216\u91cd\u65b0\u555f\u52d5 iptables \u670d\u52d9\u6642\uff0c\u7cfb\u7d71\u986f\u793a\u201cUnit iptables.service failed to load\u201d\u7684\u932f\u8aa4\u4fe1\u606f\u3002\u9019\u500b\u554f\u984c\u53ef\u80fd\u6703\u5f71\u97ff\u5230\u60a8\u7684\u9632\u706b\u7246\u8a2d\u7f6e\uff0c\u9032\u800c\u5f71\u97ff\u5230\u7cfb\u7d71\u7684\u5b89\u5168\u6027\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u9019\u500b\u554f\u984c\u7684\u539f\u56e0\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e5%95%8f%e9%a1%8c%e5%8e%9f%e5%9b%a0-LarCOMQSlB\">\u554f\u984c\u539f\u56e0<\/h2>\n<p>\u9019\u500b\u932f\u8aa4\u901a\u5e38\u662f\u7531\u65bc\u4ee5\u4e0b\u5e7e\u500b\u539f\u56e0\u9020\u6210\u7684\uff1a<\/p>\n<ul>\n<li><strong>\u7f3a\u5c11 iptables \u670d\u52d9\u6587\u4ef6\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0ciptables \u7684\u670d\u52d9\u6587\u4ef6\u53ef\u80fd\u672a\u6b63\u78ba\u5b89\u88dd\u6216\u640d\u58de\u3002<\/li>\n<li><strong>\u7cfb\u7d71\u672a\u5b89\u88dd iptables\uff1a<\/strong>\u5982\u679c\u7cfb\u7d71\u4e2d\u672a\u5b89\u88dd iptables\uff0c\u5247\u7121\u6cd5\u555f\u52d5\u8a72\u670d\u52d9\u3002<\/li>\n<li><strong>SELinux \u8a2d\u7f6e\u554f\u984c\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0cSELinux \u7684\u8a2d\u7f6e\u53ef\u80fd\u6703\u963b\u6b62 iptables \u670d\u52d9\u7684\u52a0\u8f09\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-iptables-%e6%98%af%e5%90%a6%e5%ae%89%e8%a3%9d-LarCOMQSlB\">\u6aa2\u67e5 iptables \u662f\u5426\u5b89\u88dd<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u78ba\u8a8d iptables \u662f\u5426\u5df2\u5b89\u88dd\u5728\u7cfb\u7d71\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6aa2\u67e5\uff1a<\/p>\n<pre><code>rpm -qa | grep iptables<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u8fd4\u56de\u4efb\u4f55\u7d50\u679c\uff0c\u5247\u8868\u793a iptables \u672a\u5b89\u88dd\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo yum install iptables<\/code><\/pre>\n<h2 id=\"%e6%aa%a2%e6%9f%a5%e6%9c%8d%e5%8b%99%e6%96%87%e4%bb%b6-LarCOMQSlB\">\u6aa2\u67e5\u670d\u52d9\u6587\u4ef6<\/h2>\n<p>\u5982\u679c iptables \u5df2\u5b89\u88dd\uff0c\u4f46\u4ecd\u7136\u51fa\u73fe\u932f\u8aa4\uff0c\u60a8\u9700\u8981\u6aa2\u67e5 iptables \u7684\u670d\u52d9\u6587\u4ef6\u662f\u5426\u5b58\u5728\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u67e5\u627e\u670d\u52d9\u6587\u4ef6\uff1a<\/p>\n<pre><code>ls \/usr\/lib\/systemd\/system\/iptables.service<\/code><\/pre>\n<p>\u5982\u679c\u8a72\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u60a8\u53ef\u4ee5\u624b\u52d5\u5275\u5efa\u4e00\u500b\u670d\u52d9\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684 iptables.service \u6587\u4ef6\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>[Unit]\nDescription=iptables firewall\nBefore=network-pre.target\nWants=network-pre.target\n\n[Service]\nType=oneshot\nRemainAfterExit=yes\nExecStart=\/usr\/sbin\/iptables-restore \/etc\/sysconfig\/iptables\nExecReload=\/usr\/sbin\/iptables-restore \/etc\/sysconfig\/iptables\nExecStop=\/usr\/sbin\/iptables-save &gt; \/etc\/sysconfig\/iptables\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<p>\u5c07\u4e0a\u8ff0\u5167\u5bb9\u4fdd\u5b58\u70ba \/usr\/lib\/systemd\/system\/iptables.service\uff0c\u7136\u5f8c\u91cd\u65b0\u52a0\u8f09 systemd \u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo systemctl daemon-reload<\/code><\/pre>\n<h2 id=\"%e5%95%9f%e7%94%a8%e5%92%8c%e5%95%9f%e5%8b%95-iptables-%e6%9c%8d%e5%8b%99-LarCOMQSlB\">\u555f\u7528\u548c\u555f\u52d5 iptables \u670d\u52d9<\/h2>\n<p>\u5728\u78ba\u8a8d\u670d\u52d9\u6587\u4ef6\u5b58\u5728\u5f8c\uff0c\u60a8\u53ef\u4ee5\u555f\u7528\u4e26\u555f\u52d5 iptables \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl enable iptables\nsudo systemctl start iptables<\/code><\/pre>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-selinux-%e8%a8%ad%e7%bd%ae-LarCOMQSlB\">\u6aa2\u67e5 SELinux \u8a2d\u7f6e<\/h2>\n<p>\u5982\u679c\u554f\u984c\u4ecd\u7136\u5b58\u5728\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u6aa2\u67e5 SELinux \u7684\u8a2d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b SELinux \u7684\u72c0\u614b\uff1a<\/p>\n<pre><code>sestatus<\/code><\/pre>\n<p>\u5982\u679c SELinux \u8655\u65bc\u555f\u7528\u72c0\u614b\uff0c\u60a8\u53ef\u4ee5\u66ab\u6642\u5c07\u5176\u8a2d\u7f6e\u70ba\u5bec\u9b06\u6a21\u5f0f\u4f86\u6e2c\u8a66\u662f\u5426\u662f SELinux \u5f15\u8d77\u7684\u554f\u984c\uff1a<\/p>\n<pre><code>sudo setenforce 0<\/code><\/pre>\n<p>\u5982\u679c\u9019\u6a23\u53ef\u4ee5\u89e3\u6c7a\u554f\u984c\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u8abf\u6574 SELinux \u7684\u7b56\u7565\u4ee5\u5141\u8a31 iptables \u6b63\u5e38\u904b\u884c\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-LarCOMQSlB\">\u7e3d\u7d50<\/h2>\n<p>\u5728 RHEL 7\u3001CentOS 7 \u548c Fedora \u7cfb\u7d71\u4e2d\uff0c\u9047\u5230\u201cUnit iptables.service failed to load\u201d\u7684\u554f\u984c\u901a\u5e38\u53ef\u4ee5\u901a\u904e\u6aa2\u67e5 iptables \u662f\u5426\u5b89\u88dd\u3001\u670d\u52d9\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4ee5\u53ca SELinux \u8a2d\u7f6e\u4f86\u89e3\u6c7a\u3002\u9019\u4e9b\u6b65\u9a5f\u80fd\u5920\u5e6b\u52a9\u60a8\u6062\u5fa9\u9632\u706b\u7246\u7684\u6b63\u5e38\u904b\u884c\uff0c\u78ba\u4fdd\u7cfb\u7d71\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u66f4\u591a\u7684\u6280\u8853\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u6c7a RHEL 7\u3001CentOS 7 \u548c Fedora \u4e2d\u51fa\u73fe\u7684 &#8220;Unit iptables.service failed to load&#8221; \u932f\u8aa4\uff0c\u63d0\u4f9b\u6709\u6548\u7684\u6392\u932f\u6b65\u9a5f\u548c\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-45194","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=45194"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45194\/revisions"}],"predecessor-version":[{"id":45195,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45194\/revisions\/45195"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=45194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=45194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=45194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}