1. Centos7 set up firewall and open ports
- View open ports (no ports are opened by default)
firewall-cmd --list-ports
- open port 80
firewall-cmd --zone=public (scope) --add-port= 80 /tcp (port and access type) --permanent (permanent effect)
- restart firewall
firewall-cmd --reload
- stop firewall
systemctl stop firewalld.service
- Disable firewall startup
systemctl disable firewalld.service
- delete the specified port
firewall-cmd --zone=public (scope) --remove-port= 80 /tcp (port and access type) --permanent (permanent)
2. Set firewall and open ports below Centos 7
- Open ports 80, 22, 8080
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
- keep
/etc/rc.d/init.d/iptables save
- View open ports
/etc/init.d/iptables status
- turn off firewall
- Permanent effect, will not be restored after restart
Enable: chkconfig iptables on Off: chkconfig iptables off
- Takes effect immediately, restores after restart
Start: service iptables start Shutdown: service iptables stop
- Permanent effect, will not be restored after restart