21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Guide · Hosts file

How to edit the hosts file

Quick answer

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 step-by-step hosts file guide for Windows, macOS and Linux, built around the migration-preview job Indian site owners actually need it for.

GuideWebJi®
knowledge
Read time
3 min
Sections
6
Updated
14 Nov 2026
Written by
WebJi® team

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. The override applies to this machine only. Visitors are unaffected, and the registrar's name servers do not change — that narrow effect is exactly 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 11?

On Windows 10 and 11 the file is C:\Windows\System32\drivers\etc\hosts, and you must start Notepad as Administrator or the save is denied. Open that full path, because the file dialog hides files with no extension. 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, add one IP-and-hostname line, and save. A copy in your home folder does nothing. Flush the cache afterwards 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 in your hosts file, flush the cache, and open the site: you see the new host while everyone else still sees the old one. Prove it with a file that exists only on the new server, and do not change public DNS until that check works.

  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 sequence is in 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 again. After that flush, this computer follows public DNS once more. How long other networks take is propagation — a different clock from this file, explained in how DNS propagation works.

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. Leaving the line in place is the classic mistake: your computer keeps seeing the old or new server long after everyone else has moved.

FAQ

Frequently asked questions

Does editing the hosts file change my website for visitors?

No. The override works on one computer only. Visitors, search engines and the registrar's name servers are untouched, which is why the file is the standard tool for a private preview before a migration cutover.

Why does Windows say access is denied when saving the hosts file?

The file belongs to the system, so Notepad must run as Administrator. Open the Start menu, type Notepad, choose Run as administrator, then open the full path C:\Windows\System32\drivers\etc\hosts. Editing a Desktop copy changes nothing Windows reads.

Can I put a port number like :8080 in the hosts file?

No. The hosts file maps names to IP addresses only — no ports and no protocol. To reach a non-standard port, keep the mapping here and type the port in the browser address bar, or put a reverse proxy in front of the application.

My hosts change is not working in the browser. What now?

Three usual causes: the DNS cache was never flushed, the browser uses its own secure-DNS resolver that skips the file, or the line has a typo such as http:// before the hostname. Flush the OS cache, turn off the browser's private DNS, and keep the line to IP and bare hostnames.

Is editing the hosts file safe?

Yes, with two cautions. Make a note of every line you add so you can remove it, and only edit the file yourself — a hosts file full of unknown entries is also a classic sign of malware redirecting bank and login pages, so unexplained lines deserve a security check.

Last editorial update: 15 November 2026.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.