Why nslookup works but ping and browser cannot resolve domain name?

shaopeijie 0 Reputation points
2025-02-13T05:59:50.0266667+00:00

Hi,

I’ve encountered a problem. When I execute “ping XXX” on Windows 11 (24H2), it returns “Ping request could not find host XXX” (XXX is my company’s internal network domain name), but when I execute “nslookup XXX”, it returns the correct resolution.

There are two network cards on my computer. One is connected to WAN(with IP address A), and the other is connected to LAN (with IP address B). There is a DNS server (with IP address C) in LAN, and address C can only be accessed through the LAN card. So, I set the Manual DNS server to C on the WAN card and set a static route for C (cmd: route add C mask 255.255.255.255 B).

After the settings, “ping C” works, and “nslookup XXX” can correctly resolve XXX, but “ping XXX” returns “could not find host”. I also wrote a program that calls the C library interface 'gethostbyname', and it returns the same error.

By capturing packets with Wireshark, I found that when executing “nslookup”, the DNS request is sent through the LAN card. However, when executing “ping”, it is sent through the WAN card with src A and dest C, resulting in no response to the DNS request. It seems that when executing “ping” and “gethostbyname”, the windows system ignores the rules in the static routing table.

Now I have to manually add XXX's IP to C:\Windows\System32\drivers\etc\hosts as a workaround, but it’s not convenient because the IP is changing.

May I ask if this is a problem with my settings or something else? How should I solve it? Thanks!

Windows Network
Windows Network
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Network: A group of devices that communicate either wirelessly or via a physical connection.
824 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,749 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daisy Zhou 29,471 Reputation points Microsoft Vendor
    2025-02-14T08:08:58.9933333+00:00

    Hello

    Thank you for posting in Q&A forum.

    When nslookup works but ping and other applications cannot resolve a domain name, it usually points to a DNS configuration issue.

    Here are some steps to troubleshoot this problem:

    1. Flush DNS Cache:

    ipconfig /flushdns

    1. Ensure your network adapter is configured to use the correct DNS server.
    2. Check the hosts file located at C:\Windows\System32\drivers\etc\hosts to ensure there are no incorrect entries that might be causing the issue.
    3. Open the Network Connections window (ncpa.cpl), right-click your network adapter, select Properties, and ensure the DNS settings are correct.
    4. Ensure that the DNS suffix is correctly configured. You can add a dot at the end of the domain name in the ping command to force a DNS lookup:

    ping example.com.

    1. Reset Network Settings:

    netsh winsock reset

    netsh int ip reset

    1. Temporarily disable any firewall or security software to see if they are blocking DNS requests.
    2. Try using the fully qualified domain name (FQDN) in the ping command. For example:

    ping hostname.yourdomain.com

    I hope the information above is helpful.

    If you have any questions or concerns, please feel free to let us know.

    Best Regards,

    Daisy Zhou

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.