Configure iptables firewall for CentOS

Source: Internet
Author: User
Tags centos server

Configure iptables firewall for CentOS

Yesterday, I helped my friend configure the CentOS server. At the beginning, I shut down the firewall for convenience of testing. Then I needed to configure the firewall. I found several firewall rules on the Internet with errors, later I found that the post by the blogger was not serious, and there were too many character errors. below is the configuration process of the available firewall rules I prepared:

Modify iptables-config

First, modify a configuration item in the iptables-config file.

$ Vi/etc/sysconfig/iptables-config

Change IPTABLES_MODULES = "ip_conntrack_ftp" in the last line of the file to # IPTABLES_MODULES = "ip_conntrack_ftp", that is, comment out the configuration items in that line.

Add Rules

$ Vi/etc/sysconfig/iptables

* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [5: 564]
: RH-Firewall-1-INPUT-[0: 0]
-A input-p tcp-m tcp -- dport 3306-j ACCEPT
-A input-j RH-Firewall-1-INPUT
-A forward-j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT-I lo-j ACCEPT
-A RH-Firewall-1-INPUT-p icmp-m icmp -- icmp-type any-j ACCEPT
-A RH-Firewall-1-INPUT-p esp-j ACCEPT
-A RH-Firewall-1-INPUT-p ah-j ACCEPT
-A RH-Firewall-1-INPUT-m state -- state RELATED, ESTABLISHED-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 53-j ACCEPT
-A RH-Firewall-1-INPUT-p udp-m state -- state NEW-m udp -- dport 53-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 22-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 25-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 80-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 8080-j ACCEPT
-A RH-Firewall-1-INPUT-p tcp-m state -- state NEW-m tcp -- dport 443-j ACCEPT
-A RH-Firewall-1-INPUT-j REJECT -- reject-with icmp-host-prohibited
COMMIT

It already contains Mysql database port 3306 and Tomcat port 8080. You can add or delete ports as needed.

-------------------------------------- Split line --------------------------------------

Disable the default firewall in CentOS 7.0 and enable the iptables firewall.

Iptables examples

Linux Firewall iptables

Basic use of iptables backup, recovery, and firewall scripts

Detailed description of firewall iptables usage rules in Linux

-------------------------------------- Split line --------------------------------------

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.