AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 143334
Accepted
Álvaro González
Álvaro González
Asked: 2016-07-09 04:33:40 +0800 CST2016-07-09 04:33:40 +0800 CST 2016-07-09 04:33:40 +0800 CST

仅允许从特定 IP 地址进行远程访问

  • 772

如果我理解了我所读到的内容,那么为了允许远程访问 SQL Server,您需要做的就是在 Windows 防火墙中打开 TCP 端口 1433。但这将使您的服务器对整个 Internet 完全开放,并且 SQL Server 本身没有提供进一步的工具来微调连接源。

有没有办法只允许来自已知静态 IP 地址的连接访问此类端口?

sql-server-2014 windows-server
  • 3 3 个回答
  • 9172 Views

3 个回答

  • Voted
  1. Best Answer
    Ali Razeghi - AWS
    2016-07-09T08:43:54+08:002016-07-09T08:43:54+08:00

    为此,我使用 Windows 防火墙和 Powershell。当然,除非您想获得 ScaleArc 之类的东西来充当反向代理。您的选择实际上将仅限于利用其中一种技术的东西。防火墙/IPSec 或反向代理。

    这是我用来验证此环境中存在规则的端口并添加它的脚本大纲。指定 -RemoteAddress 以限制对某些 IP 的访问:

    New-NetFirewallRule Docs

    -RemoteAddress<String[]>
    Specifies that network packets with matching IP addresses match this rule. 
    This parameter value is the second end point of an IPsec rule and specifies the computers that are subject to the requirements of this rule. 
    This parameter value is an IPv4 or IPv6 address, hostname, subnet, range, or the following keyword: Any. 
    The acceptable formats for this parameter are: 
    -- Single IPv4 Address: 1.2.3.4 
    -- Single IPv6 Address: fe80::1 
    -- IPv4 Subnet (by network bit count): 1.2.3.4/24 
    -- IPv6 Subnet (by network bit count): fe80::1/48 
    -- IPv4 Subnet (by network mask): 1.2.3.4/255.255.255.0 
    -- IPv4 Range: 1.2.3.4 through 1.2.3.7 
    -- IPv6 Range: fe80::1 through fe80::9 
    Note: Querying for rules with this parameter can only be performed using filter objects. See the Get-NetFirewallAddressFilter cmdlet for more information
    

    .

    Powershell脚本:

    ##Internal SQL Endpoint for AGs to communicate together. Needed on all nodes.
    $LocalPortNumber = '5122'
    $PortDisplayName = 'SQL-AG-Endpoint'
    $Protocol = 'TCP'
    $PortCheck = Get-NetFirewallPortFilter | where {$_.LocalPort -eq $LocalPortNumber}
    if ($PortCheck){  ##Check if exists))
    write-host "Port $($LocalPortNumber) for $($PortDisplayName) already found. Not adding Firewall Entry" #-ForegroundColor DarkGreen
    }
    ELSE
    {
    write-host "Port $($LocalPortNumber) is not found. Adding now" 
    New-NetFirewallRule -DisplayName "$($PortDisplayName)" -Direction Inbound –LocalPort $($LocalPortNumber) -Protocol $($Protocol) -Action Allow
    }
    
    • 2
  2. Álvaro González
    2016-07-12T02:55:42+08:002016-07-12T02:55:42+08:00

    Windows 防火墙允许开箱即用地按 IP 地址进行过滤,只是在“新建规则”向导中没有为您提供选择。您必须先创建规则,然后编辑其属性:

    特性

    范围

    • 2
  3. Jason B.
    2016-07-09T08:26:35+08:002016-07-09T08:26:35+08:00

    您可以通过您的网络和路由/交换基础设施来控制它。每当我遇到类似情况时,我们的网络团队都会将访问 SQL 所在子网的权限限制为某些子网。例如,您希望您的内部开发人员能够访问开发系统,但不能访问生产系统。您不仅可以通过 Windows ID 或 SQL 用户来限制这一点,还可以为 SQL 所在的子网打开路由/隧道,来往/来自开发人员所在的子网。因此,您不仅可以控制 Windows/ SQL 帐户,但也按子网/网络。

    • 1

相关问题

  • 如何在 SQL Server 升级搞砸数据库快照后“hack-drop”它

  • SQL Server - 服务用户帐户和许可?[关闭]

  • 无法将我的分发数据库 postgres 9.2 备份恢复到我的登台数据库 postgres 9.3

  • 多语句事务中不允许使用 ALTER DATABASE 语句

  • 无法连接到在 Windows 8 Hyper V 虚拟机上运行的 Oracle 数据库

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve