193 字
1 分鐘
Can't Connect to DB? Use Hosts to Force IP Binding to Resolve DNS Issues
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
hostswith “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
ipconfig /flushdns- To avoid using old DNS results
3. Verify Effectiveness
- Use
pingornslookupto confirm resolution results
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 Setting10.10.0.1 test.database.windows.net
# Clear DNSipconfig /flushdns
# Verifyping test.database.windows.netWrap-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/