0

Suppose, I type the website name www.yahoo.com in my browser. Forward DNS lookup will fetch us the IP address of the server but how does the client (browser) know the port number that the application is running on?

Amit
  • 3
  • 1
  • It doesn't. DNS doesn't resolve ports. There are exceptions for some specific applications that use TXT records for this, but generally DNS doesn't provide ports, only IP addresses. – Gerald Schneider Jan 10 '20 at 11:48
  • @GeraldSchneider Hi, thanks for the answer. I'm going through the link that you have provided but I can't seem to figure out how the port is resolved. Could you help, please? – Amit Jan 10 '20 at 11:54
  • @GeraldSchneider Port 80 is the default port, is it? If yes, then almost all the websites accessible on the web are deployed on port 80 on their respective servers? – Amit Jan 10 '20 at 11:58
  • DNS doesn't have anything to do with the actual connection to the server. Web servers run/listen on port 80 or 443 by convention. Your browser is programmed to connect to websites on port 80 or 443, barring a different port number in the URL. If the website isn't running on port 80 or 443 then your browser wouldn't connect to it, unless you append the port number to the URL in the address bar. – joeqwerty Jan 10 '20 at 12:37
  • @joeqwerty Thank you so much for the response. – Amit Jan 10 '20 at 12:38
  • Glad to help... – joeqwerty Jan 10 '20 at 12:39
  • A lot of applications/protocols have a [default port](https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers) that they operate on that you need not usually specify (eg ftp:20/21,ssh:22, telnet:23,mstsc/rdp:3389) until you are using a non-standard port (and have no redirection in place) – Smock Jan 10 '20 at 13:57
  • @Smock Thank you for the response. – Amit Jan 13 '20 at 08:46

1 Answers1

1

As long as we talk about web browsing it is rather trivial.

Suppose you write http://example.com. The browser will then connect to port 80. Likewise https://example.com will connect to port 443.

A web server can also be configured to run on an alternate port instead (like for instance port 8080).

In that case you need to write: http://example.com:8080/ (or https if the site is encrypted).


However there are other times when you use different applications to connect to a service like IMAP, SMTP, SIP (IP telephone) or the like.

It is possible to enter hostname, port numbers etc manually, but for the not so tech savy people, they prefer as much plug&play as possible.

DNS has the answer: Service records!

For instance you could have the following DNS entries:

_imap._tcp.example.com   IN SRV mail.example.com 10 60 143 43200
_smtp._tcp.example.com   IN SRV mail.example.com 10 60 25 43200
mail.example.com               IN A 1.2.3.4

The way it works is say you have an email address user@example.com. When you setup your mail client for the first time it will initially ask what is your username and password and find out the rest on it's own.

The mail client will in turn do a DNS lookup saying: "Where is the IMAP service for example.com?"

DNS will reply back: "The host mail.example.com has the IMAP service and it is running on port 143".

The following DNS entry says: mail.example.com has the IP address 1.2.3.4.

And the same procedure goes for SMTP.


From end users point-of-view all they see is they were ask for username and password and the next thing was the mail client said: "Everything has been setup.You are good to go.".

Wikipedia has a nice explanation of SRV records in more details that what I can write here.

See: https://en.m.wikipedia.org/wiki/SRV_record