Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-17-2008, 09:36 PM   #1
LQ Newbie
Registered: Apr 2008
Posts: 4

Rep: Reputation: 0
Unhappy Is there a way to recover the content of /etc/hosts file?

I am new to linux (unix in general) and while exercising "tr" command from
one of my school books, I end up erasing the content of the /etc/hosts file and then I read the following note:
#Do not erase the following line, or various programs
# that require network functionality will fail.

I use cat command to see which line my book was referring to and found that
the file is empty.

So, my question is how to fix this problem. Is there a way to know to recover the content of that file? How.

I'm using a Mac OS X (10.5 ) Leopard on the Intel iMac.
Old 04-17-2008, 10:05 PM   #2
Registered: Jan 2008
Distribution: RHEL, CentOS, Ubuntu
Posts: 379

Rep: Reputation: 38
Stick this in there and the "various programs" should be ok.

# Do not remove the following line, or various programs
# that require network functionality will fail.       localhost.localdomain   localhost
You may also need to add a line for the ip address and hostname that your machine uses if you are running network servers.

Last edited by frndrfoe; 04-17-2008 at 10:06 PM.
Old 04-18-2008, 12:44 AM   #3
Registered: Nov 2007
Location: Provo, Utah
Distribution: Debian and Ubuntu
Posts: 74

Rep: Reputation: 15
I don't know how things are in Mac, but that file shouldn't be accessible by regular users, only the administrator account (root). Don't play around learning stuff as root, you might break something.
Old 04-18-2008, 12:48 AM   #4
LQ Guru
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Quote: localhost Selena

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
The second line is only required if your computer has a name; if it has, don't forget to substitute Selena with the actual one.
Old 04-18-2008, 05:02 AM   #5
Registered: Apr 2008
Posts: 100

Rep: Reputation: 15
empty vhosts

If you don't run a public web server or any other server services to the outside world, then an empty /etc/vhosts file will do not much harm. You will not be able to access your local Apache web server as localhost, if you have one , but that's probably all.

You have been lucky that only /etc/hosts got destroyed. Be careful.



Last edited by marquardl; 05-01-2008 at 03:52 AM.
Old 04-18-2008, 09:45 AM   #6
Registered: Jan 2008
Distribution: RHEL, CentOS, Ubuntu
Posts: 379

Rep: Reputation: 38
mis spoke... ignore

Last edited by frndrfoe; 04-18-2008 at 09:46 AM.


file recovery

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to create a new file including content from reading another file !? silverhand Programming 2 10-06-2007 04:33 PM
Show file Content on File Select HTML stranger_6_7 Linux - General 4 09-24-2007 11:52 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
does the /etc/hosts file work same as the M$ hosts file? Lleb_KCir Linux - Software 6 04-03-2004 04:33 PM
How do I recover the content of /etc/modules.conf? billhull Red Hat 2 12-17-2003 07:39 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:33 PM.

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