Windows 7 hostname lookup fails if not connected to the internet
Hello, I have several client/server applications. They are well tested and run on many Unix platforms and Windows versions. They work just fine on my Windows 7 laptop when I am connected to the internet. However, when I do not have an internet connection, the host name lookup fails. Specifically, I am using GetAddrInfo in C++ and InetAddress.getLocalHost in Java. I am not trying to lookup a remote computer, the lookup is for the laptop itself, either using it's actual name or using localhost. Both work correctly when the internet is available, and fail when it is not. Both work correctly on many other platforms. I'm assuming there is some setting somewhere that is directing this behaviour, but have not been able to find it. Any help would be greatly appreciated. Dave
January 5th, 2011 4:28pm

You're not the only one who's noticed this. Let's see if I can explain - unlike previous versions, Windows 7 relies almost exclusively on DNS for name resolution and this includes LOCALHOST. Why they did this I can't say, but I've heard several theories ranging from "for security reasons" to "the death of IPv4". Thus if you're not connected to a network with DNS there's no name resolution, not even for LOCALHOST. There's a note about this change in the HOSTS file, but no reason is given. To fix it, just add "127.0.0.1 localhost" back into the hosts file - without the quotes.
Free Windows Admin Tool Kit Click here and download it now
January 5th, 2011 8:44pm

What results do you get when you try to ping LOCALHOST while the network isn't connected? If you get results like this: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\bobr>ping localhost Pinging Cierra.edcodie.com [::1] with 32 bytes of data: Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms Ping statistics for ::1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms Then it's not reading your HOSTS file correctly and is using the IPv6 LOCALHOST address. Make sure the editor you used to modify HOSTS didn't save it with a .txt extension Edit: A quick search shows me that some users had to add it to the LMHOSTS.SAM file as well in order to get it to work properly with some 3rd-party programs. You might try this too.
January 6th, 2011 10:07am

Thanks for the response. Unfortunately, I already have a 127.0.0.1 localhost entry in my hosts file. It fails for localhost and all the other entries in my hosts file as well.
Free Windows Admin Tool Kit Click here and download it now
January 6th, 2011 11:07am

When I have just 127.0.0.1 localhost in my hosts file, then ping returns: Reply from 127.0.0.1: bytes =32 time<1ms TTL=128 Reply from 127.0.0.1: bytes =32 time<1ms TTL=128 Reply from 127.0.0.1: bytes =32 time<1ms TTL=128 Reply from 127.0.0.1: bytes =32 time<1ms TTL=128 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms If I add a '::1 localhost' then I see results as in your post above, so looks like it's looking for IPV6 first, then IPV4. Adding the entry to lmhosts.sam doesn't change the behaviour at all.
January 6th, 2011 11:19am

What results do you get when you try to ping LOCALHOST while the network isn't connected? If you get results like this: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\bobr>ping localhost Pinging Cierra.edcodie.com [::1] with 32 bytes of data: Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms Ping statistics for ::1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms Then it's not reading your HOSTS file correctly and is using the default IPv6 address. Make sure the editor you used to modify HOSTS didn't save it with a .txt extension
Free Windows Admin Tool Kit Click here and download it now
January 6th, 2011 11:57am

Hi Dave, Would you please let me know if any router or switch is used? Is WINs available? Normally the Name Resolution Order is: cache -> broadcast. If a request cannot be addressed by cache, the task will be transfer to next process. you could check the cache by taking following command: IPCONFIG /displaydns http://technet.microsoft.com/en-us/library/cc758108(WS.10).aspx and try clear the cache as below command: ipconfig /flushdns You can also refer following articles for more information: NetBIOS over TCP/IP Name Resolution and WINS (http://support.microsoft.com/kb/119493/) Use NSlookup http://support.microsoft.com/kb/200525 Regards, SimidaPlease remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
January 9th, 2011 10:35pm

Hi Dave, Would you please let me know if any router or switch is used? Is WINs available? Normally the Name Resolution Order is: cache -> broadcast. If a request cannot be addressed by cache, the task will be transfer to next process. you could check the cache by taking following command: IPCONFIG /displaydns http://technet.microsoft.com/en-us/library/cc758108(WS.10).aspx and try clear the cache as below command: ipconfig /flushdns You can also refer following articles for more information: NetBIOS over TCP/IP Name Resolution and WINS (http://support.microsoft.com/kb/119493/) Use NSlookup http://support.microsoft.com/kb/200525 Regards, SimidaPlease remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
January 10th, 2011 4:34am

Hi Dave, Would you please let me know if any router or switch is used? Is WINs available? Normally the Name Resolution Order is: cache -> broadcast. If a request cannot be addressed by cache, the task will be transfer to next process. you could check the cache by taking following command: IPCONFIG /displaydns http://technet.microsoft.com/en-us/library/cc758108(WS.10).aspx and try clear the cache as below command: ipconfig /flushdns You can also refer following articles for more information: NetBIOS over TCP/IP Name Resolution and WINS (http://support.microsoft.com/kb/119493/) Use NSlookup http://support.microsoft.com/kb/200525 Regards, SimidaPlease remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
January 10th, 2011 4:34am

Hello Simida, The problem occurs when I am using the laptop with no internet connection available, so there is no router or switch and WINs is not available. I have client/server applications that I wish to run in this configuration with the client and server both running on the Windows 7 laptop. I would prefer to be able to connect using the host name as I always have in the past, but would accept at least being able to use localhost. For testing purposes I have created a new hosts file that has only one entry: 127.0.0.1 localhost I also created a lmhosts.sam file that has the same entry. With a cleanly booted machine, ipconfig/display dns shows: Windows IP Configuration 1.0.0.127.in-addr.arpa ---------------------------------------- Record Name . . . . . : 1.0.0.127.in-addr.arpa. Record Type . . . . . : 12 Time To Live . . . . : 86400 Data Length . . . . . : 8 Section . . . . . . . : Answer PTR Record . . . . . : localhost localhost ---------------------------------------- Record Name . . . . . : localhost Record Type . . . . . : 1 Time To Live . . . . : 86400 Data Length . . . . . : 4 Section . . . . . . . : Answer A (Host) Record . . . : 127.0.0.1 localhost ---------------------------------------- Record data for type AAAA could not be displayed. Attempts to connect fail. If I connect to the internet, then everything works. Simply put, I want Windows to be able to resolve localhost with internet being available, as it was able to do in previous versions. -Dave
Free Windows Admin Tool Kit Click here and download it now
January 10th, 2011 11:36am

As was mentioned previously, there was a change in behavior and it was to correct a security issue. This change was made in Windows Vista. Unfortunately I don't have any details beyond that. If you do not have an active network interface, then name resolution will not be attempted. Adding a loopback adapter should give you the behavior you are looking for. Regards, Clark Satter Microsoft Online Community Support Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
January 21st, 2011 3:10pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics