Enable iptables firewall for CentOS

Source: Internet
Author: User

Enable iptables firewall for CentOS

CentOS used iptables as the firewall before 7.0 and firewall after 7.0. In fact, I don't know why, but most people use iptables, so I also use it.

1. Disable firewall

 
1 // stop firewall
2 sudo systemctl stop firewalld. service
3 // disable firewall startup
4 sudo systemctl disable firewalld. service

2. Install the iptables firewall.

1. Install

1 // install
2 sudo yum install iptables-services

2. Configuration

// Edit iptables. If the permission is insufficient, use sudo
Vi/etc/sysconfig/iptables
// File Content
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [0: 0]
-A input-m state -- state ESTABLISHED, RELATED-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-I lo-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
-A input-j REJECT -- reject-with icmp-host-prohibited
-A forward-j REJECT -- reject-with icmp-host-prohibited
COMMIT
// Save the file
C + C and then: wq exit-> because of the habit of emacs, Here C Represents Ctrl, And so C + C is actually Ctrl + C, which will be easy to write in the future.
// Restart the firewall to make the configuration take effect
Sudo systemctl restart iptables. service
// Set firewall startup
Sudo systemctl enable iptables. service

OK. Now, your iptables has been configured. If you want to add a port later, proceed to the next step.

3. open ports

// Replace * with the port number you want to open
/Sbin/iptables-I INPUT-p tcp -- dport *-j ACCEPT
// Save the Configuration
/Etc/rc. d/init. d/iptables save
// View the changed iptables
/Etc/init. d/iptables status
// Restart iptables
Sudo service iptables restart

Well, these are some basic configurations related to iptables, which are extremely difficult. I hope you can tell me about them.

For more iptables tutorials, see the following:

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

Iptables firewall settings in Linux

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.