How do I backup the Hosts file?

Discussion in 'OS X Mountain Lion (10.8)' started by yonyz, Sep 24, 2013.

  1. yonyz macrumors newbie

    Joined:
    Jul 29, 2012
    #1
    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.
     
  2. MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #2
    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.
     
  3. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #3
    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.
     

Share This Page