Solved

Difference between 127.0.0.1 and [localhost]

Posted on 2003-12-05
10
10,127 Views
Last Modified: 2012-08-13
Hi,

Can anyone explain to me what the difference between 127.0.0.1 and localhost is?

Some people I have spoken to say they are the same. Howerver, I have had the situation where when I try to view pages on hosted on an IIS 5.0 based machine (ie my XP Pro machine) one address may work and the other may not? ie, I can view them [the pages] using 127 but not using localhost - and vice versa.

Any suggestions?

AArnie.
0
Comment
Question by:AArnie
10 Comments
 
LVL 49

Expert Comment

by:sunray_2003
Comment Utility
Go to this place in windows xp   c:\windows\system32\drivers\etc\hosts
and check that file has something like

127.0.0.1 localhost

Both are same

Sunray
0
 
LVL 11

Expert Comment

by:Zontar
Comment Utility
Your machine name should also map automatically to 127.0.0.1/localhost.
0
 
LVL 5

Accepted Solution

by:
Insolence earned 50 total points
Comment Utility
I have had this problem and have researched why this occurs.  This used to happen to me a lot on linux, and happens sometimes on OS-X and Windows.  The difference is...

127.0.0.1 is an IP address, and localhost is a hostname.

That may sound more simple of an answer than you want, but after my explanation below, you'll realize, this really is what the difference is.

First, 127.0.0.1 is an IP address.  If you go to http://127.0.0.1 in your browser, your browser instantly knows where to go, it knows to try 127.0.0.1, which is the IP address of the loopback device on your computer.

Second, localhost is a hostname.  If you go to http://localhost in your bwoser, your browser doesn't instantly know where to start looking for "localhost".  It relies on your OSes dns-resolving subsystem to come back and tell your browser that localhost is located on 127.0.0.1.  This tends to be a of your OSes dns-resolving subsystem's failure.  Basically, there's not too much you can do about this.  I have noticed this, and it pisses me off too.  I use linux as a desktop, and sometimes when I host sites on that same computer, I can use 127.0.0.1, and not localhost, or localhost and not 127.0.0.1 for some of the sites.  Rediculous!

Another thing I have found, is this sometimes is a misconfiguration of the httpd.conf (apache) or configuration of IIS.  Playing with options sometimes fixes this.  =)

 - Insolence
0
 
LVL 12

Expert Comment

by:lexxwern
Comment Utility
localhost is an alias for 127.0.0.1
0
 
LVL 2

Expert Comment

by:variant7
Comment Utility
just another related info :

All the 127.*.*.* block is a loopback IP.
When hosting several sites on the same local sever you can specify on your web server which IP belongs to which site, thus preventing the need for virtual directory use.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:fax
Comment Utility
Your browser also send the hostname you typed into the address bar in its HTTP request:
that means IIS will see if you typed:

http://127.0.0.1    - or -   http://localhost

You can tell IIS to serve different pages based on the hostname header in the HTTP request.
This is so that you can have multiple websites on your server with only one IP address.

An example is my own website. I share a server with my brother. So my domain (http://www.victorclaessen.nl) resolves to the same IP address as my brothers (http://www.felixclaessen.nl) and still if you visit those sites, you get served a different website. And if you go directly to the IP address that was resolved (http://213.84.171.80) you get another webpage still...

So maybe its a IIS configuration thing. You can check it out by starting the IIS console from Adminstrative Tools. When you right click your website and view its properties. Look at the Web Site tab. There is a button labeled 'Advanced'. There you can view/edit your settings.

Hope this helpes.

Vic
0
 

Expert Comment

by:LiamByrne
Comment Utility
To follow on from what Victor said, and to make an analogy of the setup to a telephone system..

In order to access a server, your machine needs to go to the IP address (the equivalent of a phone number).  The method by which that IP is mapped to a name, in the case of localhost/127.0.0.1, is a local settings file (which can be changed, but it's unlikely); this is the equivalent of having numbers stored in your phone.

Now, if you ring a number that only has one person at the other end, you'll get them; but if you ring a number that is shared by 2 people, you'll need to specifically ask for whichever  person you need.

So if there is more than one site hosted on the server (i.e. more than one person at the phone number) and/or the server is configured to allow more than one site and so expects you to ask for a name (in order to decide which site to serve), you won't get through.
0
 

Expert Comment

by:dittymeister2
Comment Utility
ok, when i was hosting cold fusion i ran into a little problem with my ports when i was in the testing phaze. Here was the deal. Local host and the ip of my machine seemed to work fine, but when i ran the 127.0.0.1, for some strange reason it was being blocked.  I have cable with a router, so i forwared port 80 back to myself then it allowed me to view my pages local with the 127.0.0.1 address.  cold fusion used the 127.0.0.1 for testing and it was the first time i ran into that local address...., but either way you should be able to use, 127.0.0.1 local host. ON my win2000 setup i added the address into the default web site properties. Its probably looking for your machine address, like 192.168.0.3 or whatever you use.  So, right click on default web site(or the name u use), properties, web site tab, then find the ip address its using, if you wanna see 127.0.0.1 add that in for your local testing etc..., good luck  oh ps---you can probably go to the advanced tab and add multiple names etc...
0
 

Expert Comment

by:Sahar
Comment Utility
how to mange a menu and a frame at the same page?
i have a menu below it immediately a frame ,when browsing the page the menu didnot appear above the frame
0
 

Expert Comment

by:blyths
Comment Utility
I had a similar problem in my development environment.  I was using webclasses in Visual Basic with Visual Studio - when I would try to run the code, it would try to access my website on localhost and it would fail if I was connected to a network, but would work if I disconnected or if I connected to a VPN.  It is a dns lookup problem and my ultimate solution turned out to be a simple setting in IE - in the LAN Settings, I needed to disable (clear the checkbox) under Automatic Configuration that said - Automatically detect settings.  Once I was on manual settings, everything worked fine.

Good luck.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now