Royc30ne

Royc30ne

机器学习 | 联邦学习 | VPS | 摄影 | 日常

[Linux Guide] Methods for Allowing Firewall Ports in Various Linux Distributions Centos | Ubuntu | Debian

Centos#

firewall-cmd --zone=public --add-port={PORT}/tcp --permanent

--zone                #Scope
--add-port=80/tcp     #Add port, format: port/protocol
--permanent           #Make the operation permanent, without this parameter it will be ineffective after restart

#For example, to allow port 80 for HTTP protocol, you can use the following commands:
sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reload

Ubuntu#

Ubuntu uses ufw firewall by default. To allow a port, you can use the following command:

sudo ufw allow <port>/<protocol>

#For example, to allow port 80 for HTTP protocol, you can use the following command:
sudo ufw allow 80/tcp

Debian#

Debian uses iptables firewall by default. If it is not pre-installed on the system, you can execute the following commands to install iptables:

apt-get update
apt-get install iptables
apt-get install iptables-persistent

To allow a port, you can use the following command:

sudo iptables -A INPUT -p <protocol> --dport <port> -j ACCEPT

#For example, to allow port 80 for HTTP protocol, you can use the following command:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

#Save rules (ineffective after restart)
iptables-save

#Save rules (still effective after restart)
netfilter-persistent save
netfilter-persistent reload

#View current firewall rules
iptables -L
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.