Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Localhost

Options
  • 31-01-2014 12:01pm
    #1
    Registered Users Posts: 2,815 ✭✭✭


    I've installed xampp to learn PHP. What is the story with localhost. I understand that localhost refers to "this machine" and it is processed via a loopback request.

    My questions are:
    - At what point is the requested looped back to my machine? Is it my OS, the NIC, the router, etc... Does the request actually leave my machine? At what level of the tcp/ip does it reach?

    - If the request does leave my machine, do I need an network/internet connection to access localhost?

    - What are the security implications for a home user (through UPC for example). Is localhost accessible externally or it is fully contained locally. If it is accessibly externally, how would I block external requests from accessing my PC.

    I've almost no networking experience so I'd appreciate anyone help with this.

    Cheers


Comments

  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    localhost maps to the ip 127.0.0.1. In windows, this is configured in the Hosts file.

    The request for localhost is mapped to that ip and it's not available externally. That being said, if you configure it the right way a request to localhost and an external request to your machine from another computer could be treated the same way.


  • Registered Users Posts: 1,266 ✭✭✭Overflow


    Its local as the name suggests, not externally accessible.

    127.0.0.1 is a reserved IP address corresponding to the host computer. Known as the loopback address, 127.0.0.1 is used whenever a program needs to access a network service running on the same computer as itself. Although mainly used as a testing and development address, the loopback address can be used to access local services, such as webservers, that are usually only accessed over a network and have no local interface. Additionally, most modern operating systems that implement TCP/IP regard the name "localhost" as being equivalent to 127.0.0.1.

    The address 127.0.0.1 is defined by the TCP/IP protocol as a reserved address that routes packets back to the host. Thus, no computer connected to the Internet, or any other TCP/IP compliant network, can identify itself as 127.0.0.1. The Internet Engineering Task Force's RFC 3330 defines 127.0.0.1 and 12 other special-use IPv4 addresses. Any public router or gateway that receives a packet destined for a special-use IP is required to drop it, without logging it's contents. Thus, if such a packet is accidentally forwarded outside of it's host, the packet will not accidentally arrive at another location that is willing to accept it and answer. This requirement helps provide network security, as even a machine that is configured to appear invisible on a network will likely answer packets addressed to it's loopback address. Additionally, some services may be unexpectedly activated by responding to such a stray packet.
    127.0.0.1 logo

    A successful ping request to 127.0.0.1 will verify that a computer's network interface card, it's drivers, and the operating system's TCP/IP implementation are all functioning correctly. However, in addition to it's use as a troubleshooting and local access tool.


  • Registered Users Posts: 104 ✭✭justjustin


    In an operating system, I believe that localhost goes down to driver level, between tcp/ip Internet and data layers - it doesn't go down to the data link level, meaning it doesn't go on the wire . It is a virtual (software)interface primarily used for testing the network stack on a system and connecting to local services running on that system. In the case of an operating system, nothing sent to localhost will be sent out on the wire - it will never leave your machine.

    However, there is one exception that I know of and it shouldn't concern you but is worth a mention. In the case of cisco routers (maybe others too, not sure), if you ping the routers loopback, the ping will get sent down the wire to the next hop router, which means that it does actually utilise the data link layer.


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    This probably varies by OS, but on a Windows machine you need at least one active network connection for localhost to work (even though as above nothing actually leaves the machine).

    If you don't have any network connection available, you can install the Microsoft Loopback Adaptor to simulate one and that will work just as well: http://support.microsoft.com/kb/839013


  • Registered Users Posts: 104 ✭✭justjustin


    stevenmu wrote: »
    This probably varies by OS, but on a Windows machine you need at least one active network connection for localhost to work (even though as above nothing actually leaves the machine).

    Good point, “active“ but not necessarily “connected".

    Another point is that packets directed at localhost are not framed (ethernet frames) and bypass the data link layer of the stack - this makes it impossible for the traffic to be transmitted via ethernet, ie, externally.

    This can be seen by running a wireshark capture on localhost in Linux - capture of localhost in windows is not possible, but capture of loopback is.

    In addition, using a gns3 topology with a couple of routers and a wireshark capture on the link between them, and then pinging one of the routers localhost from itself, you would see framed icmp packets going across the link.


  • Advertisement
  • Registered Users Posts: 262 ✭✭Banta


    I suppose these are the simplest answers to your questions:
    My questions are:
    - At what point is the requested looped back to my machine? Is it my OS, the NIC, the router, etc... Does the request actually leave my machine? At what level of the tcp/ip does it reach?

    The request doesn't leave your machine. It happens at the link level of TCP/IP. (Which is the lowest, if I remember correctly.)
    - If the request does leave my machine, do I need an network/internet connection to access localhost?
    It doesn't leave your machine, so... no. :)
    - What are the security implications for a home user (through UPC for example). Is localhost accessible externally or it is fully contained locally. If it is accessibly externally, how would I block external requests from accessing my PC.

    The simple answer is "no" it's not accessible externally. The more complicated answer is that if you're not secured, well, then anything can be accessed externally - running a local webserver or not :)


  • Registered Users Posts: 2,815 ✭✭✭SimonTemplar


    thanks all for your answers


Advertisement