This is because your localhost
passes your network adapter (note the LMHOSTS
in it's advanced configuration, this does in essence turn processing of the HOSTS file on and off) and your network adapter could do something extra with it. If you visit 127.0.0.1
then it directly goes to the loopback adapter, as for the other entries your network adapter might just choose to forward them instead of handling them (like the localhost
entry). You can get routing information using route PRINT
in a command prompt:
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.100 281 <--
127.0.0.0 255.0.0.0 On-link 127.0.0.1 306 <==
127.0.0.1 255.255.255.255 On-link 127.0.0.1 306 <==
127.255.255.255 255.255.255.255 On-link 127.0.0.1 306 <==
192.168.1.0 255.255.255.0 On-link 192.168.1.100 281
192.168.1.100 255.255.255.255 On-link 192.168.1.100 281
192.168.1.255 255.255.255.255 On-link 192.168.1.100 281
192.168.11.0 255.255.255.0 On-link 192.168.11.1 276
192.168.11.1 255.255.255.255 On-link 192.168.11.1 276
192.168.11.255 255.255.255.255 On-link 192.168.11.1 276
192.168.40.0 255.255.255.0 On-link 192.168.40.1 276
192.168.40.1 255.255.255.255 On-link 192.168.40.1 276
192.168.40.255 255.255.255.255 On-link 192.168.40.1 276
224.0.0.0 240.0.0.0 On-link 127.0.0.1 306
224.0.0.0 240.0.0.0 On-link 192.168.40.1 276
224.0.0.0 240.0.0.0 On-link 192.168.11.1 276
224.0.0.0 240.0.0.0 On-link 192.168.1.100 281
255.255.255.255 255.255.255.255 On-link 127.0.0.1 306
255.255.255.255 255.255.255.255 On-link 192.168.40.1 276
255.255.255.255 255.255.255.255 On-link 192.168.11.1 276
255.255.255.255 255.255.255.255 On-link 192.168.1.100 281
Note where I set the <==
at the end, these ensure that the 127.0.0.1
interface is used when you visit a loopback address.
Note where I set the <--
at the end and 0.0.0.0
means any IP, these ensure that things like localhost
, any other thing you forward in HOSTS
and most IPs you visit are handled by your network adapter which uses the 192.168.1.100
interface and the 192.168.1.1
gateway.
A higher metric means more priority, so this is why <==
has preference over <--
.
More information can be found on subnetworks to understand the netmasks.
As for your problem:
- Check your IIS/Apache configuration.
- Disable your anti virus and firewall.
- Reset your network adapter to see if it solves the problem.
- Use the
Troubleshoot Problems
option to see if it resolves something.
- Use
ipconfig /flushdns
to clear DNS resolution.
- See what you get for
ping localhost
.
- Try to disable IPv6.
- Update the drivers for your network adapter.
Report back if you still have the problem, you might want to capture a Wireshark trace.
When you install a Virtual PC instance, it's like a completely new computer, localhost
will refer to two different machines depending on if you're resolving it on the host (your physical computer) or the guest (the Virtual PC instance).
You don't have to put anything into your hosts
file to make your computer name known to the host. The host knows its own name.
You can put the name of your host into the hosts
file on the guest, but as long as they're sharing the same network, this shouldn't be required (due to Windows' peer-to-peer name resolution), but it shouldn't hurt either.
The port used by your HTTPD (IIS) will always be 80. You just have to access your host through it's network IP address (like 192.168.1.10
, not 127.0.0.1
).
In case you want to use a non-standard HTTP port (like 900), it is possible that you have to manually open that port in the Windows Firewall for your guest to be able to connect to it.
The process is outlined in this answers, but here it is adjusted for your case:
Go to the Control Panel and launch Windows Firewall.
Go to Advanced Settings
Select Inbound Rules in the left pane
Select New Rule in the right pane
In the New Inbound Rule Wizard, select Port as Rule Type, then click on Next
Select TCP and put 900 (and any other ports you want to open) in Specific
local ports, then click on Next
Select Allow the connection, then click on Next
Select the network location where the rule should apply (select them all if you're not sure), then click on Next
Give a name and an optional description
Best Answer
Kamyar, Sadly, the hosts file only associates a name to an IP address. Adding a port would make the syntax invalid.
Check out Windows HOSTS file