If I enter an IP for a website rather than the string form, does my local DNS server understand this and will I bypass the DNS process?

12

This is purely out of curiosity. But if I were to type in the IP of a website, would the request still go through the forward lookup process? If not, at what point and by which step is it realized that this is the location by IP and not a hostname as a string?

Also, how would this be recorded in my hostfile? If it goes through the entire lookup process, will the hostfile contain the string hostname as well as the IP and populate locally?

Drew D

Posted 2016-05-02T23:49:29.290

Reputation: 131

Question was closed 2016-05-03T13:18:11.463

1

Domain Name System, this is what translates a url (google.com) into the ip address, so if you use an ip address it does not have to do a name lookup, bypassing the DNS system. https://en.wikipedia.org/wiki/Domain_Name_System

– Moab – 2016-05-03T00:34:09.803

The answers below are correct, browsers are smart enough not to do a forward lookup of an IP address. Doing a forward lookup of an IP address is never a good idea, there are 3 ways a DNS server can react to it: 1) Most DNS servers will simply return the same IP address. 2) Other DNS servers cannot resolve the "dns name" to an IP and will tell you so. 3) Some (free) DNS servers cannot resolve the "dns name" and give you an IP which redirects you to their own search page (usually full of ads). – user1793963 – 2016-05-03T08:04:24.657

1Domain name is necessary if the web server hosts multiple sites. It has single IP and without domain name it cannot understand which site you want. If there is only one web site, then it will work with IP in the same way. – i486 – 2016-05-03T08:21:30.737

1Note that the hostname isn't only sent to DNS for translation, but also to the webserver itself. This means that a webserver which serves multiple websites can't know which of those sites you want. This of course is an IPv4 problem; with IPv6 every website can have its own IP address. – MSalters – 2016-05-03T08:50:35.990

1Now the next question is: How does a your browser know that 2001:feed:face:dead::beef:8080 is an IPv6 address with a specified port and not just a really badly formatted URL... ;) – Mark Henderson – 2016-05-03T11:10:00.787

Answers

15

If you use an IP address, the OS will know that it is an IP address immediately, and will not do a forward lookup.

When you do a HTTP request, the first step is to obtain the IP address of the destination, so that the browser can communicate with the server. For communication with the server, everything happens over IP, from IP address to IP address, and so the name of the server is not needed for this communication. However, it is passed in the HTTP headers as a Host: header to let the web server know which website you are after, if it is hosting multiple sites.

In the case of accessing by IP address, this does not happen, and the default site is presented.

Your hosts file is a static file, it does not change by any action you take, except if you directly edit it (or have scripts or applications that modify it).

Paul

Posted 2016-05-02T23:49:29.290

Reputation: 52 173

2Also, it is worth noting relatedly that if you enter the IP Address in a browser such as Chrome, it may do a Google search before simply loading the site. – sventechie – 2016-05-03T00:36:25.597

1Note that the internal linking of the individual objects that make up the page, is likely done by FQDN, so while the root request will run without the DNS lookup, but every image, stylesheet, script file, etc will almost certainly be resolved by DNS request when your browser attempts to render the root page and downloads all the child resources.. – Frank Thomas – 2016-05-03T01:45:48.923

2@FrankThomas In most cases, where the asset is on the same server, the assets are referenced by relative URLs and so will be accessed via the same method as the original request - via IP. The exception to this would be where base_href is used in the headers, and so dictate the host that relative URLs should use. If an FQDN is used then yes, game over. – Paul – 2016-05-03T01:57:46.250

In the case of accessing by IP address, this does not happen, and the default site is presented. You'll far more likely be given an error page. – User112638726 – 2016-05-03T08:25:40.207

@sventechie Really? Any idea why it would do that? Like, what's the value of that? – Athoxx – 2016-05-03T08:57:20.373

@User112638726 There isn't a hard and fast likelihood on this. Most of the big players would prefer you see content, and so would redirect. Smaller players may have dedicated servers and so only a single site is presented. Even smaller players on shared hosting, the host generally has a default site, often a redirect to the company page of the hosting company. There is almost never a reason to return an error when your server is accessed via IP. There are better options. – Paul – 2016-05-03T10:26:01.693

@PatrikAlienus Chrome's "OmniBox" / address bar does some fancy things and I've read that it does searches at unexpected times such as with IPs. This is useful to know when there are privacy / security concerns, for instance. – sventechie – 2016-05-03T21:19:59.837

3

As others have written, by using an IP address you are indeed skipping the DNS which allows accessing for example development sites without a host name.

Adding an IP - mock host name into /etc/hosts is extremely common again for development sites. Unlike using the IP address directly this will a) still skip DNS b) make the browser add the Host request header to the HTTP request allowing virtual hosts on a local server for example.

chx

Posted 2016-05-02T23:49:29.290

Reputation: 3 069

Its worth noting, that if for whatever reason the IP address gets updated, the HOSTS file is not updated along with it, which can lead in unexpected behavior and a site that seems to not be working anymore. Looking at the hosts file is one of the last things people do in troubleshooting an issue and may be overlooked entirely. – LPChip – 2016-05-03T08:46:54.477

@LPChip fair but please note I have emphasized several times how this is more of a developer - local practice than anything else. – chx – 2016-05-03T09:30:07.243