0

If I use foo.my-company.com at work, then all works well, but if we fix any bug remotely, then the web server will respond with a forbidden.

I heard we can use dev1-foo.my-company.com at a remote location, and it is the same site, but if I access that, I found that all the AJAX are still done to foo.my-company.com and it won't work because it is still forbidden. It seems that "hosts file" can be used to overcome this, but how specifically?

nonopolarity
  • 130,775
  • 117
  • 415
  • 675

1 Answers1

2

All a hosts file can do is associate a hostname (like dev1-foo.my-company.com) to an IP address (like 10.1.1.5).

This can be enormously useful if:

  • Your DNS doesn't have an entry for the host you need (e.g. "dev1")

    ... or ..

  • You want to override DNS (substitute your own "dev1", e.g. for testing)

This is all TCP/IP - it has nothing directly to do with higher-level protocols like HTTP or AJAX.

'Hope that helps ..

paulsm4
  • 99,714
  • 15
  • 125
  • 160
  • specifically, should I `ping dev1-foo.my-company.com` and find the IP address, let's say it is `123.12.34.56`, then add the line `123.12.34.56 foo.my-company.com` to hosts file? Also, I can only ping it to find out the IP -- I cannot `nslookup` to find it. – nonopolarity Jul 29 '13 at 05:40
  • To clarify: `forbidden` is a HTTP response, unrelated to TCP/IP and therefore not fixable at that level. Either you misunderstood your source, or they were wrong. – MSalters Jul 29 '13 at 07:09
  • actually, if I do what I said in the comment, everything works perfectly. But I am just trying to see why `nslookup` didn't work and find out what I don't know about hosts file. – nonopolarity Jul 29 '13 at 14:44
  • if you can "ping dev1-foo.my-company.com" and it gives you an IP address ... then you are *ALREADY* resolving the hostname to an IP address, and you *DO NOT NEED* to add anything to /etc/hosts. – paulsm4 Jul 29 '13 at 16:42
  • nslookup can fail for many different reasons. Perhaps the first question I'd ask: Are you running nslookup on Windows or Linux (or "something else")? Is your DNS infrastructure on Windows or Linux? I would encourage you to google for "nslookup troubleshooting" or "nslookup fails". I would also encourage you to post on http://serverfault.com, which is better suited for questions like this than SO. IMHO.. – paulsm4 Jul 29 '13 at 16:46
  • actually, wouldn't it be, even if I can ping, then it can still give me an Access Denied? For example, I can still get something back, hence the ping works, but the "something" is the content that it is access denied? – nonopolarity Jul 30 '13 at 02:32
  • Yes: even if you can ping, you can still get an "Access Denied". MSalters said it best: "To clarify: forbidden is a HTTP response, unrelated to TCP/IP and therefore not fixable at that level." Whether or not you can ping, whether you use DNS or /etc/hosts, whether or not nslookup works: *ALL* of these are unrelated to the "forbidden" HTTP response. – paulsm4 Jul 30 '13 at 03:12