59

To get to the IP address of an example website, you just visit

subdomain.example.com

However, if I try to visit

subdomain.2.1.33.111 (example ip)

Firefox returns an error.
Why?

user3236661
  • 702
  • 1
  • 6
  • 12
  • 2
    One possible workaround is to use [xip.io](http://xip.io) per [this answer](https://stackoverflow.com/a/37370422). –  Jan 01 '18 at 15:51

5 Answers5

48

All browsers will return an error for this. The reason is that subdomains are part of the DNS (Domain Name Service) system, where IP addresses are related to the underlying IP protocol.

The best way to think of this relationship is that domains (including subdomains) are human-readable labels which DNS then allows you to point to IP addresses. It would not be very catchy to have an IP address as your website on a TV ad, for example.

There is much more detail on DNS and IP addresses if you want to delve into more detail than this.

Chris Alexander
  • 1,212
  • 14
  • 19
  • 28
    The information is good however the main question was still not answered "How to access the subdomain of an IP address in the browser?"; does this mean we cannot access a subdomain without using a DNS? – Jessy Oct 10 '14 at 15:02
  • 15
    It should answer the question in that saying that an IP address has a subdomain is not a valid statement - an IP address is not a domain, thus it cannot have a subdomain. To be clear: it is not possible without DNS. – Chris Alexander Oct 11 '14 at 17:04
15

IP addresses don't support subdomains. If your goal is to serve several application on server without an assigned domain, the best way is to use ports:

2.1.33.111:8080

Some ports may already be in use or blocked for security reasons. If you need a list of some recommended ports, you could try using the same ones that Cloudflare supports.

HTTP:

  • 80
  • 8080
  • 8880
  • 2052
  • 2082
  • 2086
  • 2095

HTTPS:

  • 443
  • 2053
  • 2083
  • 2087
  • 2096
  • 8443
Pikamander2
  • 7,332
  • 3
  • 48
  • 69
MKK
  • 2,431
  • 20
  • 16
  • How would you go about using ports for this ? I have tried using ports in this way and fails to connect – ib95 May 25 '22 at 08:03
  • @ib95 You need to make sure your web server is listening to ports other than 80 (and 443). – unlut Aug 02 '22 at 13:39
13

This isn't possible via firefox. However a work around is to edit your OS hosts file see: wikipedia.

Create or edit and add a line like:

192.168.1.100 subdomain.example.com

Remember to remove the line when you're done!

jms301
  • 309
  • 2
  • 7
6

You can't mix a subdomain (DNS name) with an IP (no DNS name)

Try to use /etc/hosts file. For instance:

# IP  Hotsname    
2.1.33.111     subdomain.example.com

For Firefox It's ok but Chrome resolves names in a fancy way.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
user721730
  • 438
  • 1
  • 7
  • 11
2

A hostname is a domain (or subdomain) name that has at least one associated IP address.

The associated IP address to a domain name might differ for subdomains.

You can get the associated IP address of a domain (or subdomain) with nslookup.

Try nslookup example.com vs. nslookup subdomain.example.com to see the difference.

If firefox (or other browsers) you can either enter the hostname (e.g. example.com or subdomain.example.com) or the IP address (e.g. 11.22.33.44).

wolfrevo
  • 6,651
  • 2
  • 26
  • 38