在Linux系统中,防火墙是一个重要的安全组件,用于控制进出系统的网络流量。以下是几种常见的打开Linux防火墙设置的方法:
iptables
iptables
是Linux内核自带的防火墙管理工具。
sudo iptables -L
sudo iptables -F
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT
例如,允许SSH(端口22)和HTTP(端口80):
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables/rules.v4"
firewalld
firewalld
是另一个常用的防火墙管理工具,适用于Red Hat系列系统(如CentOS、Fedora)。
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --state
例如,开放SSH(端口22)和HTTP(端口80):
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload
ufw
(Uncomplicated Firewall)ufw
是一个简化版的防火墙管理工具,适用于Ubuntu等Debian系列系统。
sudo ufw enable
sudo ufw status
例如,允许SSH(端口22)和HTTP(端口80):
sudo ufw allow 22
sudo ufw allow 80/tcp
sudo ufw disable
iptables-save
或 firewall-cmd --reload
。通过以上方法,你可以有效地管理和配置Linux系统的防火墙,提升系统的安全性。
领取专属 10元无门槛券
手把手带您无忧上云