在Linux系统中,使用OpenSSL配置防火墙规则通常涉及以下几个步骤:
确定防火墙类型:
安装必要的软件包:
sudo apt-get update
sudo apt-get install iptables
sudo apt-get update
sudo apt-get install firewalld
sudo apt-get update
sudo apt-get install nftables
配置防火墙规则:
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT # 允许HTTPS流量
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT # 允许HTTP流量
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # 允许SSH流量
sudo iptables -A INPUT -j DROP # 拒绝所有其他流量
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=ssh
sudo firewall-cmd --reload
sudo nft add rule inet filter input tcp dport 443 accept
sudo nft add rule inet filter input tcp dport 80 accept
sudo nft add rule inet filter input tcp dport 22 accept
sudo nft list ruleset
保存防火墙规则:
sudo sh -c "iptables-save > /etc/iptables/rules.v4"
sudo firewall-cmd --runtime-to-permanent
sudo nft list ruleset > /etc/nftables.conf
重启防火墙服务:
sudo systemctl restart iptables
sudo systemctl restart firewalld
sudo systemctl restart nftables
验证防火墙规则:
sudo iptables -L -v -n
sudo firewall-cmd --list-all
sudo nft list ruleset
通过以上步骤,你可以使用OpenSSL配置防火墙规则,确保你的Linux系统安全地处理必要的网络流量。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: 在Linux中如何限制FTP用户的带宽使用