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