1

I have a web server running locally with the this address: 127.0.0.1:8000.

127.0.0.1 <-- Local IP address

8000 <-- Port number

When I use netstat command, I see the many IP addresses under the column 'local address'. All these must refer my local machine only. One of them is: 192.168.0.9 And also the series must resolve to local machine: 127.0.0.* . I verified this using ping command that this series is responding correctly.

When I reach the webserver with this URL in the browser: http://127.0.0.1:8000, it correctly returns the response from the local webserver. But what I expect is that even when I use http://192.168.0.9:8000, it must return the same response as the above one. (not that I use the same port number) But the browser is not able to reach and display 'This site can't be reached'.

Similarly when I use http://127.0.0.2:8000, I get the same error.

I don't quite understand why this happens; because the other addresses I try, must resolve to localhost and should return the message from the web server since I use the same port number which is 8000.

Not quite sure what I am doing wrong.

Journeyman Geek
  • 133,878

2 Answers2

1

Listening sockets are not necessarily bound to the host or to "every local address" – they can also be bound to a specific local address (like connected sockets usually are).

If you run netstat with the -l option (on Linux) or the -a option (Windows) and then look for the "LISTENING" socket created by your webapp, you will also see its "Local Address" column filled in – if it's 0.0.0.0 then the socket accepts connections made to any local address, but if it says e.g. 127.0.0.1 then the socket only accepts connections made to that specific address.

For example:

C:\> netstat -a -n -p tcp

Active Connections

Proto Local Address Foreign Address State TCP 0.0.0.0:445 0.0.0.0:0 LISTENING TCP 10.147.2.13:139 0.0.0.0:0 LISTENING TCP 127.0.0.1:8384 0.0.0.0:0 LISTENING

grawity
  • 501,077
-1

The whole 127.0.0.0/8 block does not resolve to the address 127.0.0.1. However, all of this block resolves to the local loopback interface. Normally, this is very fast memory-implemented interface which bypasses any local network interface hardware.

For the IP address of http://192.168.0.9 : This URL uses the local network interface hardware. However, the IP 127.0.0.1 is not found on that interface, or on any other interface. This causes the access to fail. Note that this reference will need to pass through the router, and not all routers support access from the computer to itself.

For the IP address of 127.0.0.1 : This address is the standard address for IPv4 loopback traffic; the other addresses in this IP block are not supported by all operating systems. On Windows, all the 255 IP addresses in the block can be used to set up multiple server applications on the host, all 255 listening on the same port number, but still remaining distinct.

These 255 IP addresses in the local block can then be used by different applications, all of them using the local network interface for speedy interface.

Reference :

harrymc
  • 498,455