Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If bind a socket in Python to localhost,8200 this is accessible via http://localhost:8200/. but not http://x.x.x.x:8200/

If bind a socket in Python to x.x.x.x,8200, machinename,8200 this is accessible via http://x.x.x.x:8200/ and http://machinename:8200/, but not http://localhost:8200/

I thought localhost meant 'this machine', and that using it would 'loop back' to the machine's ip address, but it appears to be different ips.

Is always a different ip address to the machines ip address?


I understand that the actual numbers are different, but what does the loopback do?

For example wikepedia says that
'pointing a web browser to the URLs or http://localhost/ will access that computer's own web site'

but that web site will also be accessible on x.x.x.x, and presumably be set up with a single socket on x.x.x.x. So how do both references work then?


I think I finally understand that and x.x.x.x work like this

-- ==\
               >- Computer
--x.x.x.x   ==/

and not

-- ==\
--------------- x.x.x.x >- Computer


--x.x.x.x ==\
--------------- >- Computer

Thanks all for the help

share|improve this question
you wrote "is always a different ip address to the machine's ip address". The numbers between the dots are different, that is a different IP address. What an odd question you ask. If by machine's ip address, you mean something other than then yes, it would be a different IP address. And if what you call your machine's IP address is (or some other standard local range), then you don't have to be afraid to say so. You can write it instead of x.x.x.x That 192 address won't exist on the internet anyway. – barlop Oct 7 '10 at 10:23
The references for both work because of how the web server is configured. You can tell the server to bind to all addresses, or to only listen on specific ones. Since the Loopback and the actual IP are distinct addresses, the configuration is determining which IP to listen on. Since localhost is just a hosts entry for, it will only work when the web server is bound to – peelman Oct 7 '10 at 14:17
up vote 14 down vote accepted

To answer your question. is not just a different ip address to the machine ip address, it's a different interface as well. should not be seen on the local network. It's a special internal IP address for the loopback adapter.

x.x.x.x will be your ethernet card.

by the way 'localhost' is simply an entry in your hosts file that points to

If you bind a socket to then only clients running locally will be able to access it and only with or http://localhost:8200 (or a dns or hosts file entry that points to

A socket bound to x.x.x.x:8200 will only be available through http://x.x.x.x:8200 or a dns or hosts file entry that points to that.

Binding a socket to does not automatically make it available on the ethernet interface as well.

Thats why you can't connect to x.x.x.x:8200

You can bind port 8200 to all available interfaces ( then it should work.

share|improve this answer
So what does the 'loopback' bit do? What does it loopback to? I thought it was a way to reference the machine ip address, whatever that happened to be' i.e. => x.x.x.x – David Oct 7 '10 at 14:03
The loopback interface is a virtual interface. It's often used to allow programs to talk to each other on the same machine. It is not a way to reference the machine IP address. IS the IP address of the loopback virtual adaptor. – Matt H Oct 8 '10 at 0:30
The other thing about the loopback adapter is that because it's virtual it doesn't actually pass any packets through to the network card. – Matt H Oct 12 '10 at 23:18
literally wasted 4 hours not understanding this concept... apparently some web servers automatically bind to both x.x.x.x and for you which elicits confusion. Great question & answer guys. Thx=) – jrhee17 May 15 at 9:34

Every IP address on the system is independent and can be bound to by sockets separately, with the exception of the special address which indicates to the OS to bind the socket to all interfaces.

share|improve this answer
But is also a special address, as the most common choice for the loopback interface. What does that address loop back to? – David Oct 7 '10 at 14:14
That doesn't make it "special", that just makes it "an address on the loopback interface" (unless you say "every address is special in its own way", but let's not go there). It's the interface that does the looping, not the address. – Ignacio Vazquez-Abrams Oct 7 '10 at 14:38

For example wikepedia says that 'pointing a web browser to the URLs or http://localhost/ will access that computer's own web site'

Slightly inaccurate. It may do so. Equally well it may not bring up any website and it is even possible to display an different internal website from what you get when you use your x.x.x.x address. points to your own machine, but that doesn't mean it will behave the same way once it reaches your machine

If you want a non-technical analogy, your can consider them different doors into your house.

There are both pointing to the same house but they are not the same thing. It is possible for each door to take you into the same room or they could take you into a different room. It is also possible to lock one door and not the other.

When you configure a website, you specify which addresses to bind to and quite often the answer is all addresses. (That is equivalent to have all doors taking you into the one room)

You can also specify the website to bind to one address only. (That is equivalent to locking all doors except one.)

If you have two (or more) websites you can bind them to separate addresses. (That is equivalent to having each door going into separate rooms).

An example of how both references work, my Windows 7 computer has IIS installed, when I go into IIS Manager and right click on Default Web Site, it gives me a 'Edit Bindings' menu option. Selecting that bring up a list of bindings. I have only one, but for IP Address it has * which means IIS listens on all my ip addresses.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .