2

Certain applications can be opened in a web browser by simply typing in localhost followed by a string of numbers eg localhost:123456

What am I really doing when I do this?

Sorry if this question sounds too simple, but the answers on the Web are not satisfactory.

For example, many answers that I found said:

operating system resolves the hostname localhost according to TCP port 123456

But this assumes that an average joe MS word document writing highschool VBA-level internet user with no knowledge of any internetworking knows what

  1. resolves means
  2. hostname means
  3. TCP port means

and how the "operating system" does all that.

Is there a more human explanation to this question?

I will start: An operating system is a software that...which when you type localhost:123456 into a web browser...it "resolves" or in other words...so that opens up your application.

  • Aren't you looking for the answer to: What happens after I type "localhost:12345" in the browser? – Henk Langeveld Sep 12 '19 at 5:25
2

Resolving means translating the human readable address: “localhost” in to a computer address known as an IP address. The computer normally does this by contacting what is known as a dns server, usually set by your ISP. Ironically localhost is a special case normally stored in a local configuration that maps to itself.

“Hostnames” are human readable names like google.com, localhost, superuser.com. They allow people to enter a name or address to connect to a website or server as opposed to typing an IP address that may look like: 192.168.1.155.

TCP ports are endpoints that can allow multiple different services to communicate with a individual host. When you type “localhost” in to the address bar of a web browser the web browser actually fills in the port number 80, which is the default for web servers. Many different services use standard ports. By adding “:60344” you are telling the web browser to attempt to establish a connection with a web server at localhost address using port 60344.

Also just a FYI ports are 16 bits so the highest port number is 2^16 = 65,535. They have a reserved range of well established ports. Also when u connect to a website your computer actually opens a dynamic port to communicate with the server. So although you are connecting to port 80 your local port will not be 80.

Please understand I tried to keep the explanation simple there is much more involved in each step. My goal was to give an overview.

For more information on ports: here

| improve this answer | |
  • Thank you very much! If I have any questions I might let you know – Cauchy's Carrot Sep 12 '19 at 1:45
0

localhost is a hostname, and there's a file in your system that tells your pc that localhost resolves to 127.0.0.1 [or ::1: if its ipv6] - which always points back at your system. We'll come to that shortly.

Practically the big problem with using 'just' IPs is they're hard to remember and you can't change them that easily if you actually want to find things later.

A hostname is a friendlier way to name things - but the back end of the internet is still machines. Hostname resolution is pretty much a way to bridge hostnames and ip addresses.

nslookup tells you what resolves where

C:\Users\faile>nslookup localhost
Server:  UnKnown
Address:  192.168.2.1

Name:    localhost
Addresses:  ::1
          127.0.0.1

compare this to say nslookup for superuser.com

C:\Users\faile>nslookup superuser.com
Server:  UnKnown
Address:  192.168.2.1

Non-authoritative answer:
Name:    superuser.com
Addresses:  151.101.1.69
          151.101.65.69
          151.101.129.69
          151.101.193.69

Name service resolution happens in 2 ways.

(The first 2 lines are my router. We'll come to that)

There's a text file somewhere on the system called a hosts file. Think of this as a post it on your phone with phone numbers written on it. It scales terribly, and you don't need all those phone numbers.

In most modern settings, we use DNS servers instead. Essentially these are a way to look up what IP is associated with what server (like a phonebook) that's updated periodically based off a set of 'master' records that are updated.

There's also a list of known ports - and for http that's port 80 and https that's port 443. If the port is not explicitly specified - it will assume that its the default port.

Now to show this a useful tool is netstat - in this case I'm using netstat -ban which shows Binary names All connections and Numbers (as opposed to names).

There's a lot there but here's the useful part for us

  TCP    192.168.2.121:49800    151.101.1.69:443       ESTABLISHED
 [vivaldi.exe]

You see 2 IP addresses - My PC (192.168.2.121) makes a connection througn port 49800 to 151.101.1.49 (which as we've determined, is Super User) via port 443.

Why port 443?

Because I'm posting this answer - and am connected to Super User via https

Looking at my browser

enter image description here

You will notice the lack of explicit port.

So basically when not explicitly set your browser needs to be told 2 things

  1. The host - this can be numeric (in theory, I can connect to 151.101.1.69 and reach the server I am getting data from, but there's a deeper rabbithole involving cache servers, load balancers and other such fun stuff) or a hostname. This is essential.

  2. A protocol - for a web browser, there's only a narrow band of possible protocols. If its not explicitly stated, the client will assume the well known port for the service. You can explicitly state a port, since you often cannot host from a default port. Your client will connect using a high, random port however.

At a deeper level, TCP and UDP are not something the end user worries about too much. They're independent ways of sending messages over IP and its typically only important when opening a port. They're good for different things, and that's about it.

| improve this answer | |
0

Here is a simple way to look at:

  • Resolving - This simply means looking something up. Just like real world buildings, everything on the Internet has an address.
  • Hostname - The name of the server you are looking up. When you look up a business in the phone book or Google, you look for it by name.
  • TCP port - Just like buildings might have multiple different people & businesses in them, the port is the correct "door" to talk to them.

So when you type localhost:12345 your computer looks up (resolves) where "localhost" is to get its address. Localhost happens to be the hostname for your computer. Now that it has your address, it needs to know which door (TCP port) to talk to. That's it.

| improve this answer | |
  • Very excellent! – Cauchy's Carrot Sep 12 '19 at 2:28
  • What I don't quite get is why would my computer have a hostname. When I interact with my computer on a day to day basis, I never encounter this "server" thing. When I open my windows laptop, the first thing I see is "Hello Windows", not "Server starting up at port 123456". When I open my C: drive, I do not get a notice "Server opens C drive Now". So where is this hostname for my computer? Where is this server? If it is a program, can I open it? If it is a file, where is it located? And where does my web browser come in? – Cauchy's Carrot Sep 12 '19 at 2:51
  • @Cauchy'sCarrot Unless you have a need to know how all this works, I wouldnt worry about it. Otherwise, I suggest reading general computer books to learn more. – Keltari Sep 12 '19 at 3:22
  • @Cauchy'sCarrot however if this was a useful answer, be sure to upvote/mark it is an answer. – Keltari Sep 12 '19 at 3:28
  • Ok, although I do not have enough rep – Cauchy's Carrot Sep 12 '19 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.