Guide · Hosts file

How to edit the hosts file

The hosts file maps a hostname to an IP on one computer, before public DNS is asked. Use it to open a migrated site on the new server while everyone else still reaches the old one. The line does not move the domain. Delete it after public DNS changes, or your test will hide the live site.
A man in a navy polo tapes a cardboard box beside an open laptop in a stock room.

What is the local hosts file and how does it override public DNS?

The hosts file is plain text on your computer. A line pairs an IP with a hostname, and the system reads it before any public resolver. That override applies to this machine only. Visitors are unaffected, and the registrar's name servers do not change. That narrow effect is why the file is safe for a private preview.

203.0.113.10 example.com www.example.com

Replace 203.0.113.10 with the new server IP. That sample address is a documentation range, not a WebJi® server. One line can name the bare domain and www. A hash starts a comment. Do not put a port number in this file.

How do you edit the hosts file as Administrator on Windows 10 and Windows 11?

On Windows 10 and 11 the file is C:\Windows\System32\drivers\etc\hosts. Start Notepad as Administrator or the save is denied. Open that full path, because the dialog hides files with no extension. Add one line with the IP, a space, and the hostname, then save and flush the DNS cache. A copy on the Desktop is not the file Windows reads.

  1. Open the Start menu, type Notepad, and choose Run as administrator.
  2. Open C:\Windows\System32\drivers\etc\hosts by typing the full path.
  3. Add the IP and hostname, save, and close Notepad.
  4. Open Command Prompt and run ipconfig /flushdns.
  5. Reload the site. Do not test a copy saved on the Desktop.

How do you edit /etc/hosts with sudo nano on macOS and Linux?

On macOS and Linux the file is /etc/hosts, writable by root only. Run sudo nano /etc/hosts and add one IP-and-hostname line, then save. A copy in your home folder does nothing. Flush the cache and test in a browser that uses the system resolver, not a private DNS setting of its own.

sudo nano /etc/hosts

In nano, add the line, then write the file and exit. On macOS flush with dscacheutil -flushcache and killall -HUP mDNSResponder, using sudo. On current Linux, resolvectl flush-caches. A browser that sends DNS to its own private resolver can ignore the file, so turn that mode off for the test.

How do you preview a migrated website on its new server IP before changing nameservers?

Map the live hostname to the new server IP, flush the cache, and open the site. You should see the new host while others still see the old one. Prove it with a file that exists only on the new server. Do not change public DNS until that check works. The cutover sequence is in the downtime guide.

  1. Get the new server IP from the migration notes.
  2. Map the live hostname to that IP in your hosts file.
  3. Flush the local cache and open the hostname on this computer only.
  4. Confirm a marker file that exists only on the new server.
  5. Leave public DNS alone until that check passes.

The public cutover is how to migrate a website without downtime. If WebJi® should do the move, that work is the website migration service. Any free move is a separate offer and is subject to terms and approval.

How do you revert your hosts file and flush your local DNS cache?

Revert by deleting the line you added, saving the file, and flushing the local cache. On Windows the command is ipconfig /flushdns. On macOS use dscacheutil and restart mDNSResponder. On current Linux use resolvectl flush-caches. After that flush, this computer follows public DNS again. How long other networks take is propagation, which is a different clock from this file.

ipconfig /flushdns
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
resolvectl flush-caches

Run only the command that matches your operating system. Then delete the extra hosts line and flush again. The delay everyone else sees is how DNS propagation works, which this file does not control.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →