{"id":610,"date":"2011-02-16T14:33:53","date_gmt":"2011-02-16T06:33:53","guid":{"rendered":"http:\/\/kaoru.tech\/?p=610"},"modified":"2011-10-16T23:58:58","modified_gmt":"2011-10-16T15:58:58","slug":"iptables","status":"publish","type":"post","link":"http:\/\/kaoru.tech:7000\/wordpress\/?p=610","title":{"rendered":"iptables"},"content":{"rendered":"<p>\u73a9\u4e865\u5e74\u7684linux\uff0c\u6ca1\u6709\u7ed9\u670d\u52a1\u5668\u52a0\u4e0a\u9632\u706b\u5899\uff0c\u4eca\u5929google\u4e86\u4e00\u4e0b\uff0c\u6574\u4e86\u4e2a\u4e1c\u897f\u51fa\u6765<\/p>\n<h2>\u9996\u5148\u770b\u5f53\u524d\u7684\u914d\u7f6e\uff0c\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff1a<\/h2>\n<pre lang=\"unix\">iptables \u2013L<\/pre>\n<p><\/p>\n<p>\u8f93\u51fa\u4fe1\u606f\u7c7b\u4f3c\u4e8e\uff1a<\/p>\n<pre lang=\"unix\">Chain INPUT (policy ACCEPT)\ntarget     prot opt source               destination\n\nChain FORWARD (policy ACCEPT)\ntarget     prot opt source               destination\n\nChain OUTPUT (policy ACCEPT)\ntarget     prot opt source               destination<\/pre>\n<p>\u8fd9\u8868\u660e\u4efb\u4f55\u4eba\u53ef\u4ee5\u4ece\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u3002<\/p>\n<h2>\u4fdd\u5b58iptables\u89c4\u5219\u5230\u6587\u4ef6<\/h2>\n<p>\u5efa\u7acb\u4e00\u4e2a\u6d4b\u8bd5iptables\u6587\u4ef6<\/p>\n<pre lang=\"unix\">vi \/etc\/iptables.rules<\/pre>\n<p>\u5728\u8fd9\u4e2a\u6587\u4ef6\u5199\u5165\u4e00\u4e0b\u7b80\u5355\u7684\u89c4\u5219 <\/p>\n<pre lang=\"vim\">*filter\n\n# Remove all rules\n-F\n\n# Allows all loopback (lo0) traffic\n-A INPUT -i lo -j ACCEPT\n\n# Accepts all established inbound connections\n-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT\n-A FORWARD -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT\n-A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT\n\n# Allows all outbound traffic\n# You could modify this to only allow certain traffic\n-A OUTPUT -j ACCEPT\n\n# Allows HTTP and HTTPS connections from anywhere\n-A INPUT -p tcp --dport 80 -j ACCEPT\n-A INPUT -p tcp --dport 443 -j ACCEPT\n\n# Allows SSH connections for script kiddies\n-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT\n\n# Allows MYSQL (Allow Remote Access To Particular IP):\n-A INPUT -p tcp --dport 3306 -j ACCEPT\n\n# Allows FTP Active mode\n-A INPUT -p tcp --dport 20:21 -j ACCEPT\n\n# Passive FTP Ports Maybe: (Again, specifying ports 50000 through 50050 in one rule)\n-A INPUT -p tcp --dport 50000:50050 -j ACCEPT\n\n# Allow ping\n-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT\n\n# log iptables denied calls (access via 'dmesg' command)\n-A INPUT -m limit --limit 5\/min -j LOG --log-prefix \"iptables denied: \" --log-level 7\n\n# Reject all other inbound - default deny unless explicitly allowed policy:\n-A INPUT -j REJECT\n-A FORWARD -j REJECT\n\nCOMMIT<\/pre>\n<p>\u8fd9\u4e2a\u770b\u8d77\u6765\u6709\u70b9\u590d\u6742\uff0c\u4f46\u662f\u6bcf\u6b21\u770b\u4e00\u8282\uff0c\u4f60\u4f1a\u53d1\u73b0\u9664\u4e86\u6211\u4eec\u5141\u8bb8\u7684\u7aef\u53e3\uff0c\u5176\u4ed6\u6240\u6709\u7aef\u53e3\u90fd\u88ab\u5173\u95ed\u4e86\u3002<\/p>\n<p>\u542f\u7528\u8fd9\u4e9b\u65b0\u7684\u89c4\u5219<\/p>\n<pre lang=\"unix\">iptables-restore < \/etc\/iptables.rules <\/pre>\n<p>\u5728\u770b\u770b\u4e0d\u540c<\/p>\n<pre lang=\"unix\">iptables -L<\/pre>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4fdd\u5b58\u8fd9\u4e9b\u89c4\u5219\u5230\u6587\u4ef6<\/p>\n<p>\u786e\u4fdd\u5728\u91cd\u542f\u540e\u8fd9\u4e9biptables\u89c4\u5219\u751f\u6548\uff0c\u5efa\u7acb\u65b0\u6587\u4ef6<\/p>\n<pre lang=\"unix\">vi \/etc\/network\/if-pre-up.d\/iptables<\/pre>\n<p>\u589e\u52a0\u5982\u4e0b\u5185\u5bb9<\/p>\n<pre lang=\"vim\">#!\/bin\/sh\n\/sbin\/iptables-restore < \/etc\/iptables.rules<\/pre>\n<p><\/p>\n<p>\u8fd9\u4e2a\u6587\u4ef6\u9700\u8981\u53ef\u6267\u884c<\/p>\n<pre lang=\"unix\">chmod +x \/etc\/network\/if-pre-up.d\/iptables<\/pre>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li>\n<p><a title=\"http:\/\/wiki.debian.org\/iptables\" href=\"http:\/\/wiki.debian.org\/iptables\">http:\/\/wiki.debian.org\/iptables<\/a><\/p>\n<\/li>\n<li>\n<p><a title=\"http:\/\/www.howtoforge.com\/linux_iptables_sarge\" href=\"http:\/\/www.howtoforge.com\/linux_iptables_sarge\">http:\/\/www.howtoforge.com\/linux_iptables_sarge<\/a><\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u73a9\u4e865\u5e74\u7684linux\uff0c\u6ca1\u6709\u7ed9\u670d\u52a1\u5668\u52a0\u4e0a\u9632\u706b\u5899\uff0c\u4eca\u5929google\u4e86\u4e00\u4e0b\uff0c\u6574\u4e86\u4e2a\u4e1c\u897f\u51fa\u6765 \u9996\u5148\u770b\u5f53\u524d\u7684\u914d\u7f6e\uff0c\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff1a iptables \u2013L \u8f93\u51fa\u4fe1\u606f\u7c7b\u4f3c\u4e8e\uff1a Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[8,25],"tags":[74],"class_list":["post-610","post","type-post","status-publish","format-standard","hentry","category-debian","category-my-server","tag-iptables"],"_links":{"self":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=610"}],"version-history":[{"count":3,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/610\/revisions"}],"predecessor-version":[{"id":935,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/610\/revisions\/935"}],"wp:attachment":[{"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kaoru.tech:7000\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}