Editing your hosts file lets you point a domain to any server without changing DNS records. This is useful when you need to preview a site on a new server before switching nameservers or when testing changes in a staging environment.
Your hosts file maps domain names to IP addresses locally on your computer. When you add an entry, your system checks this file before querying external DNS servers. This allows you to override public DNS and connect directly to a specific server.
You need the IP address of the server where your site is hosted. You can find this in cPanel or WHM depending on your access level.
In cPanel, the shared IP address appears in the General Information section on the right side of the dashboard immediately after logging in.

In WHM, navigate to List Accounts to see the IP address assigned to each cPanel account on the server.

Windows stores the hosts file in a protected system directory. You need to open your text editor with administrator privileges to make changes.

C:\Windows\System32\Drivers\etc and press Enter. This folder contains your system’s network configuration files.
hosts (with no extension) and click Open.
192.0.2.1 yourdomain.com. Replace the IP address and domain with your actual values. This tells your computer to connect to that IP address whenever you access the domain.
Ctrl+S or click File then Save. Your changes take effect immediately for new connections.ipconfig /flushdns and press Enter. This clears any cached DNS records and forces Windows to use your new hosts file entry.
You can disable a host entry without deleting it by adding a # symbol at the start of the line. This comments out the entry so your system ignores it.

macOS stores the hosts file in the /etc directory. You can edit it using Terminal or through Finder with a text editor.
Command+Space to open Spotlight, type Terminal and press Enter. Terminal provides command-line access to system files.sudo nano /etc/hosts and press Enter. Enter your administrator password when prompted. The nano text editor opens with your hosts file loaded.192.0.2.1 yourdomain.com. Replace these with your actual values.Ctrl+X to exit, then press Y to confirm saving changes, then press Enter to write the file.sudo killall -HUP mDNSResponder and press Enter. This clears macOS’s DNS cache and applies your hosts file changes immediately.Alternatively, you can use Finder to access the hosts file. Press Command+Shift+G in Finder, type /etc and press Enter. Open the hosts file with TextEdit or your preferred text editor, make your changes and save with Command+S. You still need to flush the DNS cache using the Terminal command above.
Linux distributions store the hosts file at /etc/hosts. You need root privileges to edit it.
Ctrl+Alt+T or click the Terminal application in your system menu. This provides command-line access to system files.sudo nano /etc/hosts and press Enter. Enter your password when prompted. The nano text editor opens with your hosts file loaded.192.0.2.1 yourdomain.com. Replace these with your actual values.Ctrl+X to exit, then press Y to confirm saving, then press Enter to write the file.sudo systemctl restart network-manager and press Enter. This applies your hosts file changes across all network connections. Some distributions may use NetworkManager instead of network-manager.Your hosts file now points your domain to the specified server. You can preview your site without changing DNS records or affecting other users. This is particularly useful when migrating your website to a new host or testing changes in a staging environment.
Remember to remove or comment out your host entries once you finish testing. Leaving them active prevents your computer from accessing the live site if DNS records change. You can also use a temporary domain as an alternative testing method. Our web hosting plans include staging environments for testing changes before going live.
Launch your website with our reliable cPanel hosting with unlimited bandwidth and expert support.
Get cPanel Hosting