How to filter all ports except 80, 443, 22, 3306 ports using firewalld on CentOS 7?
I searched unix.stackexchange.com, find this about iptables.
but how to block every port except special ports by firewalld?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityHow to filter all ports except 80, 443, 22, 3306 ports using firewalld on CentOS 7?
I searched unix.stackexchange.com, find this about iptables.
but how to block every port except special ports by firewalld?
CentOS 7 uses firewalld
by default.
If firewalld
is enabled and running, then all ports are blocked by default unless they were enable at install (which is usually done with ssh which is port 22 unless it's set to run on another port in /etc/ssh/sshd_config
) or enabled by the person managing the system.
Start and enable the service:
systemctl start firewalld
systemctl enable firewalld
Open the ports:
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=443/tcp
firewall-cmd --permanent --zone=public --add-port=22/tcp
firewall-cmd --permanent --zone=public --add-port=3306/tcp
Reload firewalld
firewall-cmd --reload
To show the open ports:
firewall-cmd --list-ports
Adding Port in Public Zone