为什么mssql使用dns服务而不使用主机文件来解析主机地址

时间:2019-01-14 08:00:13

标签: sql-server django dns

我使用localhost作为Django数据库的主机,但是我无法连接到它,当我将“ 127.0.0.1”用作数据库主机时,它将正常运行。如果我ping localhost.localhost将解析为127.0.0.1。但是,如果我运行nslookup localhost,我的dns服务器会将本地主机解析为另一个IP地址。

我的点冻结:

   Django==2.1.5
   django-pyodbc-azure==2.1.0.0
   djangorestframework==3.9.0
   pyodbc==4.0.25
   pytz==2018.9

我的设置:

DATABASES = {
    'default': {
        'NAME': 'my_database',
        'ENGINE': 'sql_server.pyodbc',
        'USER': 'SA',
        'PASSWORD': 'test2019!',
        'HOST': 'localhost',
        'PORT': '1433',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
        },
    }
}
# holegots @ HolegotsMBP in ~/cute_cat on git:master x [15:11:37]
$ sqlcmd -S localhost,1433 -U SA -P 'test2019!'
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2AF9.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
# holegots @ HolegotsMBP in ~/cute_cat on git:master x [15:12:34]
$ nslookup localhost
Server:     202.102.227.68
Address:    202.102.227.68#53

Non-authoritative answer:
Name:   localhost.HOST
Address: 218.28.144.38
# holegots @ HolegotsMBP in ~/cute_cat on git:master x [15:15:10] C:1
$ ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.072 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.182 ms
^C
--- localhost ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.072/0.127/0.182/0.055 ms
# holegots @ HolegotsMBP in ~/cute_cat on git:master x [15:50:47]
$ sqlcmd -S 127.0.0.1,1433 -U SA -P 'test2019!'
1> quit

我的/etc/hosts

# holegots @ HolegotsMBP in ~/cute_cat on git:master x [15:56:38]
$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost

我想知道为什么它不使用主机fils连接主机。

0 个答案:

没有答案