193 字
1 分鐘
瀏覽次數
Can't Connect to DB? Use Hosts to Force IP Binding to Resolve DNS Issues
2025-07-25
2026-04-13

Conclusion#

  • Use Hosts to directly map “IP → Hostname” to bypass DNS, quickly verify or fix connection issues.

Where It’s Useful#

  • Test environment DNS not yet configured
  • Incorrect DB / API hostname resolution
  • VPN / Private Link causing DNS to point to the wrong IP
  • Want to force connection to a specific machine (for debugging)

Steps#

1. Modify the Hosts File#

  • Go to path C:\Windows\System32\drivers\etc
  • Open hosts with “Administrator” privileges
  • Add a line mapping IP to hostname, directly overriding DNS resolution
10.10.0.1 test.database.windows.net
  • The local machine will prioritize this setting and no longer query DNS

2. Apply Settings#

  • After saving, it may not take effect immediately; you need to flush the DNS cache
Terminal window
ipconfig /flushdns
  • To avoid using old DNS results

3. Verify Effectiveness#

  • Use ping or nslookup to confirm resolution results
Terminal window
ping test.database.windows.net
  • If the IP displayed is 10.10.0.1, it means the setting is successful

Additional Notes#

  • Hosts only affects the “local machine”, not others
  • If connection is abnormal, prioritize checking for old Hosts entries
  • Azure / Private Endpoint connections can often be misdiagnosed due to Hosts overrides

Commands / Examples Summary#

Click to expand
# Hosts Setting
10.10.0.1 test.database.windows.net
# Clear DNS
ipconfig /flushdns
# Verify
ping test.database.windows.net

Wrap-up#

  • Hosts is the fastest “force redirection tool”, but remember to clear it after use, don’t cause trouble for your future self
Can't Connect to DB? Use Hosts to Force IP Binding to Resolve DNS Issues
https://joyceowo.github.io/posts/en/23ba78ea09fa81299cfad8077223fb1e/
作者
JoyceOwO
發佈於
2025-07-25
許可協議
CC BY-NC-SA 4.0