在Debian上配置SQL Server防火墙规则的步骤
确保已在Debian系统上安装SQL Server,并完成基本配置(如设置SA密码)。若未安装,可通过以下命令完成安装:
sudo apt update
sudo apt install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup # 按提示设置SA密码
要让防火墙规则生效,需先确保SQL Server本身允许远程连接:
mssql-conf工具开启TCP/IP协议并设置端口(默认1433):sudo mssql-conf set network.tcpip_enabled true
sudo mssql-conf set network.tcp_port 1433
sudo systemctl restart mssql-server # 重启服务使配置生效
sqlcmd执行以下命令,启用远程连接功能:EXEC sp_configure 'remote access', 1;
RECONFIGURE;
UFW(Uncomplicated Firewall)是Debian默认的防火墙管理工具,操作简单:
sudo apt install -y ufw
sudo ufw enable
sudo ufw allow 1433/tcp
sudo ufw status # 应显示“1433/tcp ALLOW”
若需更细粒度的控制,可使用iptables:
sudo apt install -y iptables
sudo iptables -A INPUT -p tcp --dport 1433 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4 # Debian 9及以上
/etc/network/if-pre-up.d/iptables,内容如下:#!/bin/sh
/sbin/iptables-restore < /etc/iptables/rules.v4
sudo chmod +x /etc/network/if-pre-up.d/iptables
从远程机器使用SQL Server客户端(如SSMS)测试连接:
192.168.1.100)sudo ufw allow from <IP地址> to any port 1433/tcp(UFW)或iptables的-s参数实现。