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

yonyz

macrumors member
Original poster
Jul 29, 2012
33
0
Hi,

I'd like to make some changes to the Hosts file. I know how to do it in Terminal but I'd like to have a backup of the current Hosts file in case things go awry.

Could you please guide me on how to do that?

Thank you.
 

MacUser2525

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

I'd like to make some changes to the Hosts file. I know how to do it in Terminal but I'd like to have a backup of the current Hosts file in case things go awry.

Could you please guide me on how to do that?

Thank you.

In Terminal type in then hit enter key.

Code:
sudo cp /etc/hosts /etc/hosts.backup

You will need to type in your password. Alternatively you can just make your changes in the existing file just adding a comment to know what you did, an original /etc/hosts files content.


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

Changed.

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

# Added by me to have this IP address resolve to my example domain.

192.168.0.100 example.domain.com


Anything that has a # character in front of it on a line is considered a comment and is ignored by the system. This is an easy way on a Unix system to document your changes in configuration files to remind yourself in the future why you did it and what was changed. You can just duplicate an existing line commenting one out for instance to make a change still keeping the original intact.
 

ChrisA

macrumors G5
Jan 5, 2006
12,918
2,170
Redondo Beach, California
Hi,

I'd like to make some changes to the Hosts file. I know how to do it in Terminal but I'd like to have a backup of the current Hosts file in case things go awry.

Could you please guide me on how to do that?

Thank you.

use the copy command "cp" like this

Code:
cp /etc/hosts .

The above will copy the hosts file to the current directory (dot always refers to where ever you are or "here"). You don't need to be root or use sudo, every can read /etc/hosts.

type
Code:
man cp
for more info on the copy command.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.