修改對映地址

weixin_33782386發表於2017-09-12

有時候,當我們在虛擬機器上的Linux上部署了服務後,需要給Linux對應的ip設定一個域名便於訪問,這個時候就可以來操作

找到 C:\Windows\System32\drivers\etc 目錄下的hosts檔案,在最後一行新增你要對映的地址和域名,如這樣:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

192.168.0.107   develop.sqlb.org

本人遇到了一個特別坑的問題,就是當我修改了域名後,怎麼也訪問不到對應的服務,可能是DNS域名解析到了一個已經快取的地址,就跳轉了。網上說可以這麼操作來清除DNS快取,如下:

ipconfig /flushdns

但我試了,並沒有什麼暖用。這時候,我們可以使用ping操作,

ping develop.sqlb.org

發現,能過ping通,說明我的設定操作是正確的。
哎,這個時候,我不得不修改成了另一域名再去訪問,結果當然是成功了。

相關文章