How to Access a Subdomain of a Website Hosted on an IP Address: A Developer’s Guide


2 views

When working with websites accessible only via IP address (e.g., http://192.168.1.100), accessing subdomains presents unique technical hurdles. Unlike traditional domain-based setups where DNS handles subdomain resolution, IP-based systems require alternative approaches.

The most reliable method involves modifying the HTTP Host header. Here's a Python example using the requests library:


import requests

headers = {
    'Host': 'subdomain.example.com'
}
response = requests.get('http://192.168.1.100', headers=headers)
print(response.text)

For development environments, edit your system's hosts file to map the subdomain to the IP:


# Linux/Mac: /etc/hosts
# Windows: C:\Windows\System32\drivers\etc\hosts

192.168.1.100    subdomain.example.com

When working with server configurations, set up Nginx to route subdomains:


server {
    listen 80;
    server_name subdomain.example.com;
    location / {
        proxy_pass http://192.168.1.100;
        proxy_set_header Host $host;
    }
}

Quickly test subdomain access from terminal:


curl -H "Host: subdomain.example.com" http://192.168.1.100

For Chrome-based browsers, use extensions like "ModHeader" to inject Host headers. Firefox users can modify about:config settings or use the "Header Editor" extension.

Remember that IP-based access often bypasses SSL/TLS protections. Always verify you're working in a secure development environment before implementing these solutions in production.


When working with IP-accessible websites that require subdomain access, developers often face a fundamental DNS/routing dilemma. Unlike standard domain-based configurations where DNS handles subdomain resolution automatically, IP-based access requires manual header manipulation.

The most reliable method involves modifying the HTTP Host header in your requests. Here's how to implement this across different scenarios:

// cURL example for accessing api.192.168.1.100
curl -H "Host: api.192.168.1.100" http://192.168.1.100/v1/endpoint

# Python requests example
import requests
headers = {'Host': 'staging.192.168.1.100'}
response = requests.get('http://192.168.1.100', headers=headers)

For development environments, editing the hosts file provides a persistent solution:

# Linux/Mac hosts file entry
192.168.1.100   api.development.local

# Windows hosts file location:
# C:\Windows\System32\drivers\etc\hosts

When working with local servers, an Nginx reverse proxy can route requests properly:

server {
    listen 80;
    server_name app.server.local;
    
    location / {
        proxy_pass http://192.168.1.100;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Modern browsers block direct IP subdomain access due to security policies. These extensions can help:

  • ModHeader (Chrome/Firefox) for header modification
  • Postman/Insomnia for API testing
  • Fiddler/Charles Proxy for advanced traffic inspection

For Docker-based environments, use compose networks with custom DNS:

version: '3'
services:
  app:
    networks:
      app_net:
        aliases:
          - api.container.local
networks:
  app_net:
    driver: bridge