Royc30ne

Royc30ne

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

[Linux指南] Linux各發行版防火牆端口放行的方法 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 invalid 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 your 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 (invalid after restart)
iptables-save

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

# View current firewall rules
iptables -L
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。