阅读量:1
在Ubuntu上设置邮件服务器的防火墙通常使用 UFW (Uncomplicated Firewall) 或 iptables。以下是使用这两种工具的详细步骤:
使用UFW配置防火墙
-
安装UFW(如果尚未安装):
sudo apt update sudo apt install ufw -
启用UFW:
sudo ufw enable -
配置基本防火墙规则:
- 设置默认策略:
sudo ufw default deny incoming sudo ufw default allow outgoing - 允许必要的端口:
sudo ufw allow 25/tcp # SMTP sudo ufw allow 143/tcp # IMAP sudo ufw allow 110/tcp # POP3 sudo ufw allow 465/tcp # SMTPS sudo ufw allow 587/tcp # SMTPTLS
- 设置默认策略:
-
允许特定IP访问(可选):
sudo ufw allow from your_email_server_ip to any port 25 sudo ufw allow from your_email_server_ip to any port 143 sudo ufw allow from your_email_server_ip to any port 110 sudo ufw allow from your_email_server_ip to any port 465 sudo ufw allow from your_email_server_ip to any port 587 -
保存规则:
sudo ufw save -
验证规则:
sudo ufw status verbose
使用iptables配置防火墙
-
安装iptables(如果尚未安装):
sudo apt update sudo apt install iptables -
创建和编辑防火墙规则: 编辑
/etc/iptables.rules文件,添加如下规则:*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] # Allow established and related connections -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow loopback interface -A INPUT -i lo -j ACCEPT # Allow SSH -A INPUT -p tcp --dport 22 -j ACCEPT # Allow SMTP -A INPUT -p tcp --dport 25 -j ACCEPT # Allow IMAP -A INPUT -p tcp --dport 143 -j ACCEPT # Allow POP3 -A INPUT -p tcp --dport 110 -j ACCEPT COMMIT -
加载防火墙规则:
sudo iptables-restore < /etc/iptables.rules -
查看防火墙规则:
sudo iptables -L -n -
保存防火墙规则:
sudo netfilter-persistent save
通过以上步骤,你可以在Ubuntu邮件服务器上配置和管理UFW或iptables防火墙,确保只有必要的端口和服务能够通过,从而保护邮件服务器免受未经授权的访问。
以上就是关于“ubuntu邮件服务器防火墙设置”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm