LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2011, 12:04 PM   #1
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Rep: Reputation: 16
Firefox doesn't seem to be using /etc/hosts


I have an /etc/hosts file with different domains mapped to 127.0.0.1. Now when I'm not connected to the internet and try to access that domain name, Firefox says 'server not found' even though going to 127.0.0.1 works fine. If I am connected to the internet then all of a sudden going to that domain name works.

My best guess is that when there's no internet connection Firefox goes into some kind of offline mode which doesn't allow it to connect to anything except localhost or 127.0.0.1. Any attempts to access a name, even if that name is mapped in /etc/hosts and should be respected, never occur and the result is 'server not found'. Is there some way to get Firefox to first try /etc/hosts even when in this 'offline mode'?
 
Old 11-03-2011, 03:08 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,627

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
So, what are you running?

Could we be allowed to know your distribution?
How about your version of FIREFOX, and if it is the MOZILLA distribution or the one form your LINUX repos?

What do you find in your hosts.conf file?
Can you provide all or a portion of your hosts file?
Could we take a look at your resolv.conf file?

---
swimming works better with a little water.
 
Old 11-03-2011, 03:34 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,981

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
Host file is the first way a system looks at resolving a FQDN. The only time I know of that it doesn't is when you use a proxy.pac file.
 
Old 11-03-2011, 07:17 PM   #4
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Original Poster
Rep: Reputation: 16
I am on CentOS 6, Firefox 7.0.1 directly from Mozilla. In resolv.conf I have the following:

Quote:
nameserver 8.8.8.8
nameserver 8.8.4.4
In my hosts file I have the following:

Quote:
127.0.0.1 localhost.localdomain localhost
::1 workstation1 localhost6.localdomain6 localhost6
127.0.0.1 mydomainname
Any ideas?
 
Old 11-03-2011, 09:27 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Quote:
Originally Posted by veeruk101 View Post
I have an /etc/hosts file with different domains mapped to 127.0.0.1. Now when I'm not connected to the internet and try to access that domain name, Firefox says 'server not found' even though going to 127.0.0.1 works fine.
Unless you are running a server on localhost, this would be normal behavior when you try to connect to any website. Firefox cannot reach the DNS server, so it can't load any page by domain name.

Generally, the point of mapping valid domains (such as doubleclick dot com) to localhost is so the web browser cannot go to them when the internet connection is active. It functions as sort of a blacklist in this usage.

In my case, I get holes in the webpage where the ads are supposed to be. Which is just hunky-dory with me.

This site has an excellent description of how hosts files work in relation to internet browsing.

What would be abnormal would be Firefox's actually loading ads from doubleclick dot com or any internet address redirected to 127.0.0.1 in /etc/hosts when the internet connection is active.

Is Firefox actually going to the websites listed in your hosts file or are normal websites loading minus content provided by the blacklisted addresses?
 
Old 11-04-2011, 10:22 AM   #6
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by frankbell View Post
Firefox cannot reach the DNS server, so it can't load any page by domain name.

...

Is Firefox actually going to the websites listed in your hosts file or are normal websites loading minus content provided by the blacklisted addresses?
Yes Firefox should be actually going to the website listed in my host file, I'm not using it as a blacklist.

Though Firefox can't reach the DNS server, I was under the impression that anything resolving host names FIRST goes to the hosts file and only if it's not there it goes to the DNS server. (Isn't that the whole point?) If my internet connection is down, Firefox could still first go to the host file and complete my request rather than giving up altogether. So I'm hoping there's a way to make it behave like this.
 
Old 11-04-2011, 05:16 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,981

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
I don't see any host entry for a resolution.
 
Old 11-04-2011, 08:16 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by veeruk101 View Post
I was under the impression that anything resolving host names FIRST goes to the hosts file and only if it's not there it goes to the DNS server. (Isn't that the whole point?) If my internet connection is down, Firefox could still first go to the host file and complete my request rather than giving up altogether. So I'm hoping there's a way to make it behave like this.
The sequence in which the resolver library attempts to perform host lookups is controlled by the /etc/host.conf file. Mine looks like this:
Code:
multi on
order hosts,bind
which causes the /etc/hosts file to be checked first, followed by a name server lookup if nothing matches in the hosts file. You should have a manpage for hosts.conf that explains the details.

Syntax errors in /etc/hosts can also cause lookups there to fail.
 
Old 11-04-2011, 08:32 PM   #9
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
In your original post, if I understand it correctly, you said that

Quote:
Originally Posted by veeruk101 View Post
I have an /etc/hosts file with different domains mapped to 127.0.0.1. Now when I'm not connected to the internet and try to access that domain name, Firefox says 'server not found' even though going to 127.0.0.1 works fine. If I am connected to the internet then all of a sudden going to that domain name works.
I'm a little puzzled.

I would expect that, if you are not connected to the internet, no internet site would be accessible.

Maybe I'm misunderstanding what you were expressing when you wrote, "not connected to the internet."

I interpreted it to mean that the ethernet cable was removed or the equivalent thereof.

Is the site you're trying to hit a local server on your local network?
 
Old 11-09-2011, 09:15 AM   #10
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Original Poster
Rep: Reputation: 16
My /etc/host.conf file had only 'multi on', so I added 'order hosts,bind' but that changed nothing.

Quote:
I would expect that, if you are not connected to the internet, no internet site would be accessible.

Maybe I'm misunderstanding what you were expressing when you wrote, "not connected to the internet."

I interpreted it to mean that the ethernet cable was removed or the equivalent thereof.

Is the site you're trying to hit a local server on your local network?
I'm trying to hit a local server on my local network. So when I type 'testdomain.com' into Firefox, if that is mapped to 127.0.0.1 in /etc/hosts, I would expect Firefox to access localhost even if it's not connected to the internet. Maybe there's some Firefox setting for this? I'm really confused here. (Also, there aren't any syntax errors in my /etc/hosts because everything works fine when my internet is connected.)

I found the following blog post which describes an identical problem (http://tristram.squarespace.com/home...available.html), but his fix didn't work for me. I had previously changed network.dns.disableIPv6 in about:config to be true, but then when I tried his suggestion of changing it back to the default of false it didn't work for me...

Could it have something to do with /etc/nsswitch.conf maybe? There are several lines in that file but the one that seems to be related is 'hosts: files dns'.

Last edited by veeruk101; 11-09-2011 at 09:34 AM.
 
Old 11-10-2011, 09:50 AM   #11
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,627

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
firefox is not the network

1. if your networking is down on a machine, then even localhost access may be disabled.
2. are you running a DNS server (perhaps using dnsmasq) on your local network?
3. how does your machine running Firefox pick up and IP address (static or dhcp)?

When your external access goes away, you lose access to the google nameservers, and all name resolution will fail. Entries in the hosts file CAN resolve names, but things get a little picky. Also, if your networking checks BIND before HOSTS it will have to time out on all listed nameservers before connecting, and some software times out faster.

It strikes me that you have been referring to what Firefox uses, when what is really at question is your TCPIP networking and addressing. Firefox just happens to be the application in which you have observed the behavior.

I have cable internet access, and it has been pretty reliable. When it does go down, my access to services in my local network remains unaffected. I run my own dns and dhcp server, local WIFI, music streamer, and network storage using Debian. Under these conditions I have never seen behavior such as you describe.
 
Old 11-10-2011, 07:36 PM   #12
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Quote:
Originally Posted by veeruk101 View Post
I'm trying to hit a local server on my local network. So when I type 'testdomain.com' into Firefox, if that is mapped to 127.0.0.1 in /etc/hosts, I would expect Firefox to access localhost even if it's not connected to the internet.
Only if the server application is running on the computer as Firefox. "127.0.0.1" means "there here computer," not "this here network."

If your ip address was 192.168.1.103 and the server application is running on 192.168.1.13, /etc/hosts would have to point to 192.168.1.13.
 
Old 11-10-2011, 08:39 PM   #13
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
In the initial post, the OP indicated that going to the numeric address 127.0.0.1 worked, but using the name "localhost" resulted in "Server not found."
 
Old 11-11-2011, 02:34 PM   #14
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Original Poster
Rep: Reputation: 16
Thanks everyone for helping me through with this. It turns out that this was in fact a bug. With yesterday's release of Firefox 8.0, they also solved this issue!
 
Old 11-11-2011, 07:42 PM   #15
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Thanks for the rest of the story.
 
  


Reply

Tags
dont_use_a_hosts_file



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] DKIM doesn't Sign emails from external hosts raghugs Linux - Server 2 10-08-2009 08:35 AM
/etc/hosts doesn't always block sites General Linux - Security 16 01-23-2007 07:31 AM
hosts.deny doesn't seem to work xpucto Linux - Security 10 11-20-2006 07:03 PM
lookupd doesn't query /etc/hosts bisecT Linux - Networking 0 04-30-2005 06:46 PM
hosts.deny doesn't block an SSH attempt vmattila Linux - Security 4 11-14-2004 12:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration