To modify the file hosts in Mac and Windows

We taught to you to modify the file hosts of your operating system Mac or Windows to cause that a domain solves towards a direction IP different from which indicates its servant of DNS.

Author: Emilio C.S.
Published


What is the file hosts?

The file hosts is a flat text file used by the operating system to keep the correspondence between domain names and directions IP. In many operating systems the file hosts is used preferably with respect to other systems as the DNS to solve names of domains.

What we are going to do?

We are going to modify the file hosts of the operating system to cause that a domain solves towards a direction IP different from which indicates its servant of DNS. This change allows us for example, to accede to a our name of domain through another service of lodging Web and can helpful be (in the process of migration of a webpage) to verify that everything works correctly before the change of the DNS of the domain.

To modify the file hosts in Mac

  1. It initiates the Terminal application (Applications/Utilities/Terminal in Mac OS) and executes the following line. You will have to introduce the password of your account of user.

    I sweat nano /etc/hosts

    This is the appearance of the file hosts in Mac OS:

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

  2. It adds the following line, replaces IP by direction IP of the new service of lodging.

    IP www.tunombredominio.com

    Thus hosts would be the file modified:

    ##
    # Host Database
    #
    # localhost is used to forms the loopback interface
    # system is when the booting. Do not change this entry.
    ##
    IP www.tunombredominio.com
    127.0.0.1 localhost
    255.255.255.255 broadcasthost
    :: 1 localhost
    fe80:: 1%lo0 localhost

  3. X presses Ctrl + to close and (YES) to keep the changes.
  4. In order to clean it breaks it of resolution of names and that the changes spurt effect executes this commando (flushcache for Tiger 10,4 uses lookupd -).

    dscacheutil - flushcache

  5. In order to verify that the change is correct you do ping towards your domain, the result it must indicate that you accede to the new IP.

    ping - c1 www.tunombrededominio.com

    You will receive a result similar to this:

    ping - c1 www.tunombrededominio.com
    PING tunombrededominio.com (IP): 56 date bytes
    64 bytes from IP: icmp_seq=0 ttl=56 time=68.178 ms

To modify the file hosts in Windows

  1. It initiates the console of commandos (cmd) of Windows in way administrator. For it sees the menu Home of Windows and writes cmd in the field search. When it appears the icon of the console of commandos, you click it exceeds he with the right button of the mouse and selects To execute as administrator.
  2. You do a backup copy of the present file hosts executing the following commando:

    Copy C:\Windows\System32\drivers\etc\hosts C:\Windows\Temp

  3. Next it opens to the file hosts with the Notepad application.

    notepad C:\Windows\System32\drivers\etc\hosts

  4. It adds the following line, it replaces IP by direction IP of the new service of lodging and keeps the changes.

    IP www.tunombredominio.com

    Thus hosts would be the file modified:

    # Copyright (c) 1993-2009 Microsoft Corp.
    #
    # This is to sample HOSTS cases out used by for Microsoft TCP/IP Windows.
    #
    # This cases out contains the mappings of IP addresses to host yams. Each
    # entry should sees kept on an individual line. The IP address should
    # sees you please in the first column followed by the corresponding host yam.
    # The IP address and the host yam should sees separated by AT least one
    # space.
    #
    # Additionally, comments (such ace these) May sees inserted on individual
    # lines or following the machine yam denoted by to €˜#€™ symbol.
    #
    # For example:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

    IP www.tunombrededominio.com

    # localhost name resolution is handled within DNS itself.
    # 127.0.0.1 localhost
    #:: 1 localhost

  5. In order to clean it breaks it of resolution of names and that the changes spurt effect executes the following commando in the console of commandos of Windows:

    ipconfig /flushdns

  6. In order to verify that the change is correct you do ping towards your domain, the result it must indicate that you accede to the new IP.

    ping www.tunombrededominio.com

To recover or to recover the file temporarily hosts

Unless the changes in the file hosts are permanent, it is important that you recover the initial configuration when finalizing your tasks, you will avoid conflicts of resolution of names of domain in the future.

So that the realised changes do not spurt effect only is necessary to comment new line with a hook # and to return to execute the commando of cleaning of breaks it of resolution of names.

#IP www.dominio.com

More information