{"id":7034,"date":"2017-10-01T21:48:16","date_gmt":"2017-10-01T13:48:16","guid":{"rendered":"http:\/\/rmohan.com\/?p=7034"},"modified":"2017-10-01T21:48:16","modified_gmt":"2017-10-01T13:48:16","slug":"centos7-install-iptables-firewall","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7034","title":{"rendered":"CentOS7 install iptables firewall"},"content":{"rendered":"<p><strong>CentOS 7 default firewall is not iptables, but firewall<\/strong><\/p>\n<p><strong>Install iptable iptable-service<\/strong><\/p>\n<p><strong># First check whether the installation of iptables <\/strong><br \/>\nservice iptables status<br \/>\n# install iptables<br \/>\nyum install-y iptables<br \/>\n# upgrade iptables<br \/>\nyum update iptables<br \/>\n# install iptables-services<br \/>\nyum install iptables-services<\/p>\n<p><strong>Disable \/ stop the built-in firewalld service<\/strong><\/p>\n<p># Stop the firewalld service<br \/>\nsystemctl stop firewalld<br \/>\n# Disable the firewalld service<br \/>\nsystemctl mask firewalld<\/p>\n<p>Set up existing rules<\/p>\n<p># View iptables existing rules<br \/>\niptables -L-n<br \/>\n# first allow all, otherwise there may be a cup<br \/>\niptables -P INPUT ACCEPT<br \/>\n# clear all default rules<br \/>\niptables-F<br \/>\n# clear all custom rules<br \/>\niptables-X<br \/>\n# all counters 0<br \/>\niptables -Z<br \/>\n# Allows packets from the lo interface (local access)<br \/>\niptables -A INPUT -i lo -j ACCEPT<br \/>\n# open 22 port<br \/>\niptables -A INPUT -p tcp -dport 22 -j ACCEPT<br \/>\n# open 21 port (FTP)<br \/>\n-A -p TCP &#8211;dport the INPUT iptables 21 is -j ACCEPT<br \/>\n# open port 80 (the HTTP)<br \/>\niptables -A 80 &#8211;dport the INPUT -p TCP -j ACCEPT<br \/>\n# open port 443 (the HTTPS)<br \/>\niptables -A the INPUT -p TCP &#8211; -dport 443 -j ACCEPT<br \/>\n# Allow ping<br \/>\niptables -A INPUT -p icmp &#8211;icmp-type 8 -j ACCEPT<br \/>\n# Allow the return data after the native request RELATED, which is set for FTP<br \/>\niptables -A INPUT -m state &#8211;state RELATED, ESTABLISHED -j ACCEPT<br \/>\n# other inbound discarded<br \/>\niptables -P INPUT DROP<br \/>\n# all outbound all green<br \/>\niptables -P OUTPUT ACCEPT<br \/>\n# all forwarded<br \/>\niptables -P FORWARD DROP<\/p>\n<p>Other rules set<\/p>\n<p>Iptables -P INPUT<br \/>\n-p tcp -s 45.96.174.68 -j ACCEPT<br \/>\n# Filter all requests that are not above rules<br \/>\niptables -P INPUT DROP<br \/>\n# To block an IP, if you want to add an intranet ip trusted (accept all of its TCP requests) Use the following command:<br \/>\niptables -I INPUT -s ***. ***. ***. *** -j DROP<br \/>\n# To unblock an IP, use the following command:<br \/>\niptables -D INPUT -s * **. ***. ***. *** -j DROP<\/p>\n<p>Save the rule settings<\/p>\n<p># Save the above rules<br \/>\nservice iptables save<\/p>\n<p>Open the iptables service<\/p>\n<p># Register iptables service<br \/>\n# equivalent to the previous chkconfig iptables on<br \/>\nsystemctl enable iptables.service<br \/>\n# Open service<br \/>\nsystemctl start iptables.service<br \/>\n# View status<br \/>\nsystemctl status iptables.service<\/p>\n<p>Solve vsftpd iptables open, can not use the passive mode of the problem<\/p>\n<p>1. First modify or add the following in \/ etc \/ sysconfig \/ iptables-config<\/p>\n<p># Add the following, note that the order can not be exchanged<br \/>\nIPTABLES_MODULES = &#8220;ip_conntrack_ftp&#8221;<br \/>\nIPTABLES_MODULES = &#8220;ip_nat_ftp&#8221;<\/p>\n<p>2. Reset the iptables settings<\/p>\n<p>iptables -A INPUT -m state &#8211;state RELATED, ESTABLISHED -j ACCEPT<\/p>\n<p>The following is a complete setup script<\/p>\n<p>#! \/ bin \/ SH<br \/>\niptables -P the INPUT ACCEPT<br \/>\niptables -F<br \/>\niptables the -X-<br \/>\niptables the -Z<br \/>\niptables -A the INPUT LO -i -j ACCEPT<br \/>\niptables -A &#8211;dport 22 is the INPUT -p TCP -j ACCEPT<br \/>\niptables -A the INPUT -p tcp &#8211;dport 21 -j ACCEPT<br \/>\niptables -A INPUT -p tcp &#8211;dport 80 -j ACCEPT<br \/>\niptables -A INPUT -p tcp &#8211;dport 443 -j ACCEPT<br \/>\niptables -A INPUT -p icmp &#8211;icmp-type 8 &#8211; j ACCEPT<br \/>\niptables -A INPUT -m state &#8211;state RELATED, ESTABLISHED -j ACCEPT<br \/>\niptables -P INPUT DROP<br \/>\niptables -P OUTPUT ACCEPT<br \/>\niptables -P FORWARD DROP<br \/>\nservice iptables save<br \/>\nsystemctl restart iptables.service<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CentOS 7 default firewall is not iptables, but firewall<\/p>\n<p>Install iptable iptable-service<\/p>\n<p># First check whether the installation of iptables service iptables status # install iptables yum install-y iptables # upgrade iptables yum update iptables # install iptables-services yum install iptables-services<\/p>\n<p>Disable \/ stop the built-in firewalld service<\/p>\n<p># Stop the firewalld service systemctl stop [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7034"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7034"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7034\/revisions"}],"predecessor-version":[{"id":7035,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7034\/revisions\/7035"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}