Hosts file working partially on Fedora - linux

I am having the following /etc/hosts file :
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.10.139/azc clientdomain.com www.clientdomain.com
80.230.215.84 home_server
The first, second and fourth line are working normally. However the third isn't. I tried to look for "invisible characters" and rewrote the whole line without copy-pasting anything, but the clientdomain.com query in my browser or via ping still brings me to my client's IP address.
Am I not allowed to use paths at all in my hosts file, just sheer IP addresses?
If I take out the /azc bit, the redirection does happens correctly.
I don't manage to have it working through .htaccess redirections either...

I was actually trying to redirect a domain name to a specific folder on my server.
I finally discovered (Doh!!) that Apache has a dedicated feature for this called VirtualHost.
This post explains very well how to set one.
I hope this helps.

Related

How to use domain name instead of local host IP with PHP

I'm experimenting some PHP code with a local IP address http://192.168.33.10.
When I was using the address in a form of number (192.168.33.10) it was working fine (see image 1), but when I try to use a domain name "dev.dotinstall.com", it reaches an error page (see image 2).
I learned that you can use a name like "dev.dotinstall.com" instead of IP address by editing hosts file, so I edited it adding a line "192.168.33.10 dev.dotinstall.com" at the end of the hosts file (see image 3).
The error page says "The fact that you are seeing this page indicates that the website you just visited is either experiencing problems or is undergoing routine maintenance.", but I don't know what the problem is.
Any idea why this is happening?
You are correct that you need to add the URL into the hosts file. Make sure you have saved it correctly (with administrator rights) and the port is correct.
This is not enough though, you will need to set up a virtual host for Apache as well and then restart Apache. If you only set the URL in the hosts file, then Apache will not know what to do with it. There are plenty of materials on setting up a virtual host for Apache on Windows if you search for that.

Blocking all of tumblr from hosts file

I am trying to block tumblr, and all it's pages, using my hosts file. Usually I would just add an entry like
127.0.0.1 tumblr.com
to my file, but tumblr has websites in the format " sitename.tumblr.com"
I have tried
127.0.0.1 *.tumblr.com
127.0.0.1 http://*.tumbr.com
And neither work either. Does anyone know how to block tumblr without installing bulky software?
You can block static.tumblr.com and 78.media.tumblr.com and render the site basically unusable.
I was searching and trying to block this shitty website and finally found the solution. There is nothing you can do with hosts file, except blocking the regular form of www addresses. Personally, I recommend to use Avast blocking sites tool. It works great and blocks all the tumblr subdomains. You have to add
http://*.tumblr.com*
in your "Blocked URL address list" and enable it.

Multiple localhost:80-bound sites in IIS?

(You can skip directly to the question, but the context is on the background section.)
Technical Context
Windows 8
IIS 7
Background:
As several others, I work with IIS and from time to time I need to set up a local version of a site. Now, in setting up different sites, it is quite common to just assign them different ports so that they don't overlap. So you could have your site A at port 80, your site B at port 81 and so on.
Now, I want to setup the bindings so that I am able to have several sites under port 80 and with the header host distinction I can at the same time give meaningful URLs to these sites.
An option to do this is with adding entries to your hosts file, such as:
127.0.0.1 siteA.com
127.0.0.1 siteB.com
And with this, you should be able to browse to siteA.com or siteB.com and have that working locally.
But I want to take one more step, as localhost is already set up to match 127.0.0.1, so:
Question:
I had set up the IIS bindings as:
site host header port
siteA siteA.localhost 80
siteB siteB.localhost 80
And I expected that I would be able to browse to http://siteA.localhost/ and http://siteB.localhost/ and get my sites.
However, when I browse, it seems that my requests never reach IIS, and the address is not resolved.
Why isn't that working?
Update:
I have chosen chue x's answer because he explained why this doesn't work. For those that may follow my same path, you may think "well, I could just add *.localhost in the hosts file and it should be done." or even switch to *.local or *.localdev.com or something of that sort.
That, however, doesn't work: Wildcards in a Windows hosts file
As chue x pointed out, our only approach right now is to keep adding entries to the hosts file or, how they explain in the linked question, to use another DNS server.
Your hosts file needs to match your IIS bindings, which have to match the url browser.
So if your hosts file looks like:
127.0.0.1 siteA.localhost
127.0.0.1 siteB.localhost
Your IIS bindings need to be:
site host header port
siteA siteA.localhost 80
siteB siteB.localhost 80
Finally, from the local machine, you need to browse to:
http://siteA.localhost
EDIT - If you are trying to do the above without adding the hosts entries for siteA and siteB, it won't work. DNS won't find it. So for example, what happens if you try to browse to "foo.stackoverflow.com" - the request will fail even though "stackoverflow.com" is a known address.

Setting up a Host File - Faking URLs

I'm trying to set up my development instances so that I can fake some urls that I own. My website has a number of url's and depending on the one you visit my site will act differently based on the domain..
ive edited my C:\WINDOWS\system32\drivers\etc\hosts File to contain something like below
127.0.0.1 localhost
127.0.0.1 SomeDomain.com
127.0.0.1 MyDomain.com
Now if I visit localhost everything works fine but when i try visit SomeDomain.com or MyDomain.com it produces couple different messages depending on browsers
Firefox - "Bad Request (Invalid Hostname)"
Chrome - Asked for a username/password and just hitting on (not entering anything) products same result as firefox
IE6- "The page cannot be displayed"
any ideas?
Your HOSTS file looks good. Also try adding the www version of each one, e.g.:
127.0.0.1 localhost
127.0.0.1 SomeDomain.com
127.0.0.1 www.SomeDomain.com
etc
However, the problem is probably the setup of the web server. If you're using IIS, the problem probably is that you haven't set up host headers correctly.

How do I prevent dnsmasq from appending my domain name to invalid domain requests?

I use dnsmasq to resolve DNS queries on my home network. Unfortunately, if a domain name is not known, it will append my own domain name to the request which means that I always end up viewing my own site in a browser.
For example, if I enter http://dlksfhoiahdsfiuhsdf.com in a browser, I end up viewing my own site with that URL. If I try something like:
host dlksfhoiahdsfiuhsdf.com
Instead of the expected:
Host dlksfhoiahdsfiuhsdf.com not found: 3(NXDOMAIN)
I get this:
dlksfhoiahdsfiuhsdf.com.mydomainname.com has address W.X.Y.Z.
Clearly, dnsmasq is appending my domain name to impossible name requests in an effort to resolve them, but I'd rather see the not found error instead.
I've tried playing with the expand-hosts and domain configuration settings, but to no avail. Is there anything else I can try?
try querying with a trailing dot to explicitly set the root:
host dlksfhoiahdsfiuhsdf.com.
It is probably not dnsmasq doing it, but your local resolver library. If you use a unixish, try removing the "search" or "domain" lines from /etc/resolv.conf
There might be other causes, but the most obvious cause is the configuration of /etc/resolv.conf, and the fact that most DNS clients like to be very terse about errors.
benc$ host thing.one
Host thing.one not found: 3(NXDOMAIN)
(okay, what was I using for a DNS config?)
benc$ cat /etc/resolv.conf
nameserver 192.168.1.1
(edit...)
benc$ cat /etc/resolv.conf
search test.com
nameserver 192.168.1.1
benc$ host thing.one
thing.one.test.com has address 64.214.163.132
Without bothering to do a packet trace, the likely behavior is that it returns the error for the last FQDN it tried.
You have a wildcard domain?
dnsmasq is forwarding the appended name out to the external dns server and its getting wildcarded.
you can use --server=/yourinternaldomainhere/ to make sure that your internal domain name lookups are not forwarded out.
syntax in this case would be:
--server=/domain/iptoforwardto
and in this case leave the iptoforwardto area blank as you don't want it to forward anywhere.
I tried removing domain-needed from my own configuration to replicate your issue and it did not produce this behaviour. It's the only other parameter I could find that might be close to relevant.
What does your hosts file look like? Maybe something weird is going on there that makes it think all weird domains are local to your network?

Resources