{"id":1058,"date":"2019-05-20T13:48:01","date_gmt":"2019-05-20T05:48:01","guid":{"rendered":"https:\/\/blog.naibabiji.com\/?p=1058"},"modified":"2019-12-07T20:57:34","modified_gmt":"2019-12-07T12:57:34","slug":"bao-ta-mian-ban-fang-huo-qiang-kai-fang-duan-kou","status":"publish","type":"post","link":"https:\/\/blog.naibabiji.com\/skill\/bao-ta-mian-ban-fang-huo-qiang-kai-fang-duan-kou.html","title":{"rendered":"\u5b9d\u5854\u9762\u677f\u9632\u706b\u5899\u5f00\u653e\u7aef\u53e3_firewalld_iptables\u6dfb\u52a0\u89c4\u5219"},"content":{"rendered":"<p>\u5b9d\u5854\u9762\u677f\u5b89\u88c5\u597d\u540e\u81ea\u5e26\u4e86\u9632\u706b\u5899\uff0c\u5176\u4e2dcentos6\u7528\u7684iptables\u3001centos7\u7528\u7684firewall\u3001debian\/ubuntu\u7528\u7684ufw\u9632\u706b\u5899\u3002<\/p>\n<p>\u4e0d\u8fc7\u7531\u4e8e\u5b9d\u5854\u9762\u677f\u662f\u56fe\u5f62\u5316\u754c\u9762\uff0c\u65b0\u624b\u4e5f\u53ef\u4ee5\u5f88\u7b80\u5355\u7684\u4ece\u540e\u53f0\u6dfb\u52a0\u9632\u706b\u5899\u89c4\u5219\uff0c\u5177\u4f53\u4f4d\u7f6e\u662f\uff1a<strong>\u5b89\u5168-\u9632\u706b\u5899<\/strong><\/p>\n<h2>\u5b9d\u5854\u9762\u677f\u9632\u706b\u5899\u89c4\u5219<\/h2>\n<p>\u8fdb\u5165\u5b9d\u5854\u9762\u677f\u540e\u53f0\uff0c\u627e\u5230\u5b89\u5168\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u770b\u5230\u9632\u706b\u5899\u754c\u9762\uff0c\u8fd9\u91cc\u53ef\u4ee5\u65b0\u589e\u6216\u8005\u5220\u9664\u9632\u706b\u5899\u89c4\u5219\uff0c\u4f8b\u5982\u6dfb\u52a0\u7aef\u53e3\u6743\u9650\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1059\" src=\"https:\/\/edgeone.naibabiji.com\/wp-content\/uploads\/2019\/05\/1558237987-naibabiji.com_2019-05-19_11-48-34-compressor.png\" alt=\"firewall\u9632\u706b\u5899\" width=\"687\" height=\"469\" \/><\/p>\n<p>\u4ece\u8fd9\u91cc\u6dfb\u52a0\u9700\u8981\u7684\u89c4\u5219\u5c31\u53ef\u4ee5\u7ed9<strong>\u5b9d\u5854\u9762\u677f\u5f00\u653e\u7aef\u53e3<\/strong>\u4e86\u3002\u5982\u679c\u4f60\u60f3\u5f00\u653e\u5f88\u591a\u7aef\u53e3\uff0c\u53ef\u4ee5\u4f7f\u7528\u6a2a\u6760\u7684\u65b9\u5f0f\u6765\u6279\u91cf\u6dfb\u52a0\uff0c\u4f8b\u598220-20000\u5c31\u662f\u5f00\u653e\u4ece20\u523020000\u7684\u6240\u6709\u7aef\u53e3\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u5982\u679c\u4f60\u8d2d\u4e70\u7684\u662f<a title=\"\u67e5\u770b\u65b0\u7248\u201c\u963f\u91cc\u4e91\u201d\u4f18\u60e0\u6d3b\u52a8\" href=\"https:\/\/blog.naibabiji.com\/go\/aliyun\">\u963f\u91cc\u4e91<\/a>\u6216\u8005<a title=\"\u67e5\u770b\u65b0\u7248\u201c\u817e\u8baf\u4e91\u201d\u4f18\u60e0\u6d3b\u52a8\" href=\"https:\/\/blog.naibabiji.com\/go\/qcloud\">\u817e\u8baf\u4e91<\/a>\uff0c\u4ed6\u4eec\u7684\u7ba1\u7406\u540e\u53f0\u4e5f\u81ea\u5e26\u5b89\u5168\u7ec4\u8fd9\u4e9b\u9632\u706b\u5899\u529f\u80fd\uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u628a\u5b9d\u5854\u81ea\u5e26\u7684\u9632\u706b\u5899\u5173\u95ed\u4ee5\u8282\u7701\u8d44\u6e90\u3002<\/p>\n<h2>Linux\u7cfb\u7edf\u9632\u706b\u5899\u547d\u4ee4<\/h2>\n<p>\u4e0d\u540cLinux\u7cfb\u7edf\u5185\u7f6e\u7684\u9632\u706b\u5899\u8f6f\u4ef6\u4e0d\u4e00\u6837\uff0c\u4f8b\u5982CentOS7\u5185\u7f6e\u7684\u662ffirewalld\uff0c\u800cCentOS6\u5185\u7f6e\u7684\u9632\u706b\u5899\u662fiptables\uff0c\u6240\u4ee5\u5206\u5f00\u8bb2\u4e24\u79cd\u9632\u706b\u5899\u7684\u89c4\u5219\u547d\u4ee4\u3002<\/p>\n<h3>firewalld\u5f00\u653e\u9632\u706b\u5899\u7aef\u53e3<\/h3>\n<p>CentOS7\u5b89\u88c5\u5b9d\u5854\u9762\u677f\u5185\u7f6e\u7684\u9632\u706b\u5899\u662ffirewalld\uff0c\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>\u542f\u52a8\uff1a systemctl start firewalld<br \/>\n\u67e5\u770b\u72b6\u6001\uff1a systemctl status firewalld<br \/>\n\u505c\u6b62\uff1a systemctl disable firewalld<br \/>\n\u7981\u7528\uff1a systemctl stop firewalld<\/p>\n<p>firewalld\u5f00\u653e\u7aef\u53e3\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre>sudo firewall-cmd --zone=public --add-port=3000\/tcp --permanent\r\nsudo firewall-cmd --reload<\/pre>\n<h3>CentOS 6 iptables \u9632\u706b\u5899\u547d\u4ee4<\/h3>\n<p>CentOS 6\u4e0a\u9762\u9ed8\u8ba4\u7684\u662fiptables\u9632\u706b\u5899\uff0c\u5982\u679c\u60f3\u8981\u67e5\u770b\u9632\u706b\u5899\u662f\u5426\u8fd0\u884c\uff0c\u53ea\u9700\u8981\u8f93\u5165\u4e0b\u9762\u7684\u547d\u4ee4\u3002<br \/>\nservice iptables status<br \/>\n\u5982\u679c\u9632\u706b\u5899\u6ca1\u6709\u8fd0\u884c\u4f1a\u63d0\u793a\uff1a<br \/>\niptables: Firewall is not running.<\/p>\n<p>\u542f\u52a8iptables\u7684\u8bdd\u5c31\u8f93\u5165\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<br \/>\nservice iptables start<\/p>\n<p>\u91cd\u65b0\u542f\u52a8iptables\u7684\u8bdd\u5c31\u8f93\u5165\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<br \/>\nservice iptables restart<\/p>\n<p>\u505c\u6b62iptables\u7684\u8bdd\u5c31\u8f93\u5165\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<br \/>\nservice iptables stop<\/p>\n<h3>iptables\u9632\u706b\u5899\u5f00\u653e\u7aef\u53e3<\/h3>\n<p>\u5f00\u542fSSH\u670d\u52a1\u7aef\u53e3<\/p>\n<pre>[root@tp ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT\r\n[root@tp ~]# iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT<\/pre>\n<p>\u6ce8:\u5982\u679c\u5728\u9884\u8bbe\u8bbe\u7f6e\u628aOUTPUT\u8bbe\u7f6e\u6210DROP\u7b56\u7565\u7684\u8bdd\uff0c\u5c31\u9700\u8981\u8bbe\u7f6eOUTPUT\u89c4\u5219\uff0c\u5426\u5219\u65e0\u6cd5\u8fdb\u884cSSH\u8fde\u63a5\u3002<\/p>\n<p>\u5f00\u542fWeb\u670d\u52a1\u7aef\u53e3<\/p>\n<pre>[root@tp ~]# iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT\r\n[root@tp ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT<\/pre>\n<p>\u5f00\u542f\u90ae\u4ef6\u670d\u52a1\u768425\u3001110\u7aef\u53e3<\/p>\n<pre>[root@tp ~]# iptables -A INPUT -p tcp --dport 110 -j ACCEPT\r\n[root@tp ~]# iptables -A INPUT -p tcp --dport 25 -j ACCEPT<\/pre>\n<p>\u5f00\u542fFTP\u670d\u52a1\u768421\u7aef\u53e3<\/p>\n<pre>[root@tp ~]# iptables -A INPUT -p tcp --dport 21 -j ACCEPT\r\n[root@tp ~]# iptables -A INPUT -p tcp --dport 20 -j ACCEPT<\/pre>\n<p>iptables\u5f00\u653e\u6240\u6709\u7aef\u53e3<\/p>\n<pre>iptables -P INPUT ACCEPT \r\niptables -P OUTPUT ACCEPT<\/pre>\n<h2>\u9632\u706b\u5899\u89c4\u5219\u4e0d\u751f\u6548\uff1f<\/h2>\n<p>\u6709\u4e9b\u670b\u53cb\u53ef\u80fd\u4f1a\u78b0\u5230\uff0c\u628a\u9632\u706b\u5899\u89c4\u5219\u6dfb\u52a0\u4e86\uff0c\u4f46\u662f\u7f51\u7ad9\u8fd8\u662f\u6253\u4e0d\u5f00\uff0c\u4f8b\u5982<strong>\u9632\u706b\u5899\u5c06\u7aef\u53e3\u6253\u5f00,\u8fd8\u662f\u8fdb\u4e0d\u4e86\u5b9d\u5854<\/strong><\/p>\n<p>\u901a\u5e38\u8fd9\u79cd\u60c5\u51b5\u662f\u56e0\u4e3a\u4f60\u8d2d\u4e70\u7684\u670d\u52a1\u5668\u81ea\u5e26\u4e86\u4e00\u4e2a\u7cfb\u7edf\u5916\u7684\u9632\u706b\u5899\uff0c\u4f8b\u5982<a title=\"\u67e5\u770b\u65b0\u7248\u201c\u817e\u8baf\u4e91\u201d\u4f18\u60e0\u6d3b\u52a8\" href=\"https:\/\/blog.naibabiji.com\/go\/qcloud\">\u817e\u8baf\u4e91<\/a>\u548c<a title=\"\u67e5\u770b\u65b0\u7248\u201c\u963f\u91cc\u4e91\u201d\u4f18\u60e0\u6d3b\u52a8\" href=\"https:\/\/blog.naibabiji.com\/go\/aliyun\">\u963f\u91cc\u4e91<\/a>\uff0c\u4ed6\u4eec\u7ba1\u7406\u540e\u53f0\u6709\u5b89\u5168\u7ec4\u53ef\u4ee5\u8bbe\u7f6e\uff0c\u4f60\u9700\u8981\u53bb\u628a\u5bf9\u5e94\u7684\u89c4\u5219\u6253\u5f00\u624d\u884c\uff08\u4e5f\u5c31\u662f\u8bf4\u7cfb\u7edf\u81ea\u5e26\u7684\u9632\u706b\u5899\u53ef\u4ee5\u5173\u95ed\uff0c\u4f7f\u7528\u4ed6\u4eec\u7684\u5b89\u5168\u7ec4\u5c31\u53ef\u4ee5\u4e86\uff09<\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;1058&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;4&quot;,&quot;greet&quot;:&quot;\u7ed9\u672c\u6587\u6253\u5206 post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;\u5b9d\u5854\u9762\u677f\u9632\u706b\u5899\u5f00\u653e\u7aef\u53e3_firewalld_iptables\u6dfb\u52a0\u89c4\u5219&quot;,&quot;width&quot;:&quot;138&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 138px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            5\/5 - (1 vote)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9d\u5854\u9762\u677f\u5b89\u88c5\u597d\u540e\u81ea\u5e26\u4e86\u9632\u706b\u5899\uff0c\u5176\u4e2dcentos6\u7528\u7684iptables\u3001centos7\u7528\u7684firewall\u3001de [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1060,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"\u5b9d\u5854\u9762\u677f\u9632\u706b\u5899\u5f00\u653e\u7aef\u53e3_firewalld_iptables\u6dfb\u52a0\u89c4\u5219 - \u5976\u7238\u5efa\u7ad9\u7b14\u8bb0","description":"\u5b9d\u5854\u9762\u677f\u5b89\u88c5\u597d\u540e\u81ea\u5e26\u4e86\u9632\u706b\u5899\uff0c\u5176\u4e2dcentos6\u7528\u7684iptables\u3001centos7\u7528\u7684firewall\u3001debian\/ubuntu\u7528\u7684ufw\u9632\u706b\u5899\u3002 \u4e0d\u8fc7\u7531\u4e8e\u5b9d\u5854\u9762\u677f\u662f\u56fe\u5f62\u5316\u754c\u9762\uff0c\u65b0\u624b\u4e5f\u53ef\u4ee5\u5f88\u7b80\u5355\u7684\u4ece\u540e\u53f0\u6dfb\u52a0\u9632\u706b\u5899\u89c4\u5219\uff0c\u5177\u4f53\u4f4d\u7f6e\u662f\uff1a \u5b89\u5168-\u9632\u706b\u5899 \u5b9d\u5854\u9762\u677f\u9632\u706b\u5899\u89c4\u5219 \u8fdb\u5165\u5b9d\u5854\u9762\u677f\u540e\u53f0\uff0c\u627e\u5230\u5b89\u5168\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u770b\u5230\u9632\u706b\u5899\u754c"},"footnotes":""},"categories":[142],"tags":[],"class_list":["post-1058","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/posts\/1058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/comments?post=1058"}],"version-history":[{"count":0,"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/posts\/1058\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/media\/1060"}],"wp:attachment":[{"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/media?parent=1058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/categories?post=1058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.naibabiji.com\/wp-json\/wp\/v2\/tags?post=1058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}