Friday, April 29, 2011

How can I direct traffic to Subdomains in /etc/hosts?

I tried to put the line to /etc/hosts:

IP math.com mathworld.com

where IP was supposed to be the IP of http://mathworld.wolfram.com/classroom/. I pinged the site, and I realised that I must direct traffic with some other tools:

ping mathworld.wolfram.com/

ping: cannot resolve mathworld.wolfram.com/: Unknown host

So the question arises:

How can I direct traffic to subdomains, similar to the above subdomain?

From stackoverflow
  • Your ping failed because you had a trailing / on the hostname, which isn't valid.

    Are you trying to create your own local alias URL that drops you into the right part of that specific third-party URL?

    That can't work on its own, because:

    1. the third party site will see your hostname alias in the Host: HTTP headers, which it won't recognise
    2. it won't drop you into the right subdirectory of their server

    To make this work you'd need to point that local alias towards a web server that you control, and then have that server issue an HTTP redirect to the real site.

    ceejayoz : The bigger issue is that mathworld.wolfram.com isn't in the /etc/hosts file.
    Alnitak : Why should it be? that's what DNS is for. It looks like he's just trying to create local shortcuts for those URLs.
  • You seem to be confused about networking terminology.

    http://mathworld.wolfram.com/classroom/ is a URL, not a domain name. It has no IP address. mathworld.wolfram.com is a domain name and has an IP address.

    Also, mathworld.wolfram.com is a subdomain of wolfram.com which is a subdomain of the com top level domain.

    mathworld.wolfram.com is not a subdomain of mathworld.com

    The /etc/hosts is not powerful enough to map all subdomains of a domain to the same place. You will need to type them all out, or go into proper DNS server configuration (such as named.conf).

    Masi : Why does the command "ping mathworld.wolfram.com" do not work for me? The error is "ping: sendto: No route to host".
    Masi : If the sentence "mathworld.wolfram.com is a domain name and has an IP address" is right, the ping should work. Why does it not work?
    Artelius : Is your internet connection correctly set up? "No route to host" means the IP address was found, but cannot be reached.
    Masi : @Artelius: Yes, it is. I can access the site with any of my browsers, such as Opera and Firefox, but I cannat ping. I tested to ping in Ubuntu and Mac OS, but the same message appers. I cannot understand the reason if the site "mathworld.wolfram.com" really has an IP.
    Masi : The same error appears with the site "wolfram.com", when I do: ping wolfram.com
    Artelius : Web browers tend to have their own DNS engines built in, but ping relies on the OS's DNS system. It could be that your OS's name resolution is misconfigured.

0 comments:

Post a Comment