Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ifred1

macrumors newbie
Original poster
Sep 1, 2013
7
0
Hi :)

I've been googleing for some time now, and therefore I try this forum.
I accedently deleted my hosts file i Mountain Lion (10.8.4), and I want to bring it back. Can somebody help me on how to do so? :confused:

regards

Fred
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
Hi :)

I've been googleing for some time now, and therefore I try this forum.
I accedently deleted my hosts file i Mountain Lion (10.8.4), and I want to bring it back. Can somebody help me on how to do so? :confused:

regards

Fred

Your /etc/hosts file? If so the contents should be this.

Code:
MacUser2525:~$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

The permissions on the file.

Code:
MacUser2525:~$ ls -l /etc/hosts
-rw-r--r--  1 root  wheel   236B 19 Jan  2013 /etc/hosts

To get it back open the Terminal.app and type in then hit enter key.

Code:
sudo nano /etc/hosts

Enter your password then copy and paste the contents I posted above into file you have open in Terminal.app. Once pasted hit the Control and X keys answer yes to saving the file. Now for proper ownership and permissions type in then hit enter key the two commands below.

Code:
sudo chown root:wheel /etc/hosts
sudo chmod 0644 /etc/hosts
 

ifred1

macrumors newbie
Original poster
Sep 1, 2013
7
0
Your /etc/hosts file? If so the contents should be this.

Code:
MacUser2525:~$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

The permissions on the file.

Code:
MacUser2525:~$ ls -l /etc/hosts
-rw-r--r--  1 root  wheel   236B 19 Jan  2013 /etc/hosts

To get it back open the Terminal.app and type in then hit enter key.

Code:
sudo nano /etc/hosts

Enter your password then copy and paste the contents I posted above into file you have open in Terminal.app. Once pasted hit the Control and X keys answer yes to saving the file. Now for proper ownership and permissions type in then hit enter key the two commands below.

Code:
sudo chown root:wheel /etc/hosts
sudo chmod 0644 /etc/hosts

Hi Man

Thanks for the quick respons! I can't seem to save the content on the screen that pops up after typing
Code:
sudo nano /etc/hosts

What should I do? I've tried entering pressing cmd + x but nothing seems to happen... :-(
 

Attachments

  • Screen Shot 2013-09-02 at 10.09.40.png
    Screen Shot 2013-09-02 at 10.09.40.png
    20.7 KB · Views: 133

benwiggy

macrumors 68020
Jun 15, 2012
2,470
287
I accedently deleted my hosts file i Mountain Lion (10.8.4), and I want to bring it back. Can somebody help me on how to do so?
Restore it from your backup, which you have because you would have made one before attempting to modify any system files.

Otherwise, use TextWrangler to create and save the file, (or to edit it if a new one has been created).

TW is free and essential for the easy editing of system text files.
 

tag

macrumors 6502a
Apr 29, 2005
918
9
What should I do? I've tried entering pressing cmd + x but nothing seems to happen... :-(

The modifier is control, not command. So try control + X. You should then get a prompt asking if you want to save. Hit yes, and it will save then exit you out of nano.

Alternatively, you can also manually save first before exiting by hitting control + O, and then control + X.
 

ifred1

macrumors newbie
Original poster
Sep 1, 2013
7
0
Restore it from your backup, which you have because you would have made one before attempting to modify any system files.

Otherwise, use TextWrangler to create and save the file, (or to edit it if a new one has been created).

TW is free and essential for the easy editing of system text files.

I Confess, my timemashine was out of order... :rolleyes:
 

ifred1

macrumors newbie
Original poster
Sep 1, 2013
7
0
The modifier is control, not command. So try control + X. You should then get a prompt asking if you want to save. Hit yes, and it will save then exit you out of nano.

Alternatively, you can also manually save first before exiting by hitting control + O, and then control + X.

Got it back YEEES - Damn YOU GUYS ROCK :cool::cool::cool:!!! Thanks A LOT!!! Been trying to crack this (pardon my french) bitch, but couldn't get it done.

Now I only need to figure out the permission thing. :rolleyes:
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
Now I only need to figure out the permission thing. :rolleyes:

Disk Utility I am thinking could do it with its repair permissions option perhaps or a copy and paste of the two commands listed in my first post into the Terminal.app window will.
 

ifred1

macrumors newbie
Original poster
Sep 1, 2013
7
0
Disk Utility I am thinking could do it with its repair permissions option perhaps or a copy and paste of the two commands listed in my first post into the Terminal.app window will.

If I type in the first command just aften opening terminal I get the error:

Code:
-bash: MacUser2525:~$: command not found

Thanks again for helping me out!
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
If I type in the first command just aften opening terminal I get the error:

Code:
-bash: MacUser2525:~$: command not found

Thanks again for helping me out!

You are putting in the wrong part that is telling you it cannot find the MacUser2525 command, do it with just the commands themself sudo chown root:wheel /etc/hosts and sudo chmod 0644 /etc/hosts.
 

ifred1

macrumors newbie
Original poster
Sep 1, 2013
7
0
You are putting in the wrong part that is telling you it cannot find the MacUser2525 command, do it with just the commands themself sudo chown root:wheel /etc/hosts and sudo chmod 0644 /etc/hosts.

Okay did it with just the commands you wrote, and it seemend to work.

Another quistion you worte the code with:

Code:
MacUser2525:~$ cat /etc/hosts

on to it should only be like this right?:

Code:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

Sorry man I'm really living up to the newbie under my name and the Thread Starter :)
 

MacUser2525

Suspended
Mar 17, 2007
2,097
377
Canada
Okay did it with just the commands you wrote, and it seemend to work.

Another quistion you worte the code with:

Code:
MacUser2525:~$ cat /etc/hosts

on to it should only be like this right?:

Code:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost

Sorry man I'm really living up to the newbie under my name and the Thread Starter :)

Exactly leave out the first of it where I show the actual command I used to get the output you put in the file. Alternatively the file could look like this and still be correct as the # character has been placed in front of the part not needed making it a comment not to be read and used by the system.


Code:
#MacUser2525:~$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.