Table of contents
Have you ever found yourself in the situation that you have transferred your website to a new hosting and want to preview how it will work before pointing to the website's domain? Fortunately, this is entirely possible, and one of the most popular ways to do this is by editing your computer's hosts file.
In this article, we examine what the hosts file is and what its uses are.
What is the hosts file used for?
The hosts file is a plain text file that maps hostnames to IP addresses. It is part of every major operating system (OS) like macOS, Windows, Linux, etc.
BeforeDNSwas introduced, there was no centralized and automated system for hostname resolution. In the past, every computer or local area network relied on its hosts file, which contained a list of well-known host names and their respective IP addresses.
With the implementation of DNS, computers no longer depend on this file because they can automatically obtain hostname addresses from the DNS network.
However, the hosts file remains even in the latest operating systems (OS) as it is still useful.
You can map a selected domain to an IP address of your choice. This change is local, it only works for your computer without affecting other visitors. The most common cases where you want to use your hosts file are:
- You're launching a new website, but haven't registered a domain name yet. You can modify your hosts file to connect a non-existing domain to the hosting's IP and start building the website.
- You migrated an existing website from one hosting to another. You want to preview how the migrated website will work on the new hosting before closing your previous hosting account. So you don't want to connect your domain to the new hosting just yet, but you need to preview how the website will load from the new hosting.
- You want to block access to a website from your own computer. This is easily accomplished by pointing a website's domain to the invalid address 0.0.0.0, which creates a loopback.
How do you find your website's IP address?
The hosts file is most commonly used to force a connection between your website and a domain name that is pointed to a different address by DNS records. To do this, you must first obtain the IP address of your website.
You can usually find the address in the control panel of your hosting account. ForSiteGroundUser this is located on the siteWebsite-Tools > Dashboard> IP and Name Servers > Location IP.
To have an example for this exercise, we created a website calledmeine-neue-website.com. This domain name is unregistered, meaning it doesn't exist and has no DNS records. Any visitor who tries to open this address will see the error "This website cannot be reached".

In this case, the address is35.214.215.226which must be used when mapping in the hosts filemeine-neue-website.comto this website.
Similarly, you can create a website, name it after a domain name that DNS points elsewhere, and map the website's domain using your hosts file.
Read along to find out how to edit your hosts file depending on the operating system you are using.
How to edit hosts file in Windows 8, 10 and 11?
Editing the hosts file is essentially the same in all versions of Windows - you must edit the hosts file as wellNotepad. The only difference is that you need to run Notepad as an administrator on Windows 7 and later, while on older versions (Windows XP and earlier) this is not mandatory.
However, regardless of the Windows version, the default location of the Windows hosts file is the same unless you installed the operating system on a different partition:
C:\Windows\System32\drivers\etc\hosts
Step 1.Open Notepad from the Windows menu
In this guide, we are going to edit the hosts file on Windows 10. First, click on theWindowsIcon (Start Menu).
Start typingnotepad,which automatically activates the search function. The first result will beNotepad. Right-click the icon and select itExecute as administrator.
Step 2.Open the hosts file in Notepad
In the Notepad window, click thefilemenu and selectOpen minded,which opens a file selection box.
Make sure you selectAll filesotherwise thehostFile does not appear in the dialog because it is a hidden file and not a.txtRenewal. Navigate to the hosts file path, select the file and pressOpen minded.
Step 3.Edit the hosts file
Windows 10's hosts file is pretty much the same as on any other operating system. It contains a few lines that define the address for the local host and other services, although note that they are commented with the "#" symbol. This means that they are not activated, just left as examples.
To add your custom hostname settings, add a new line to the end of the file and omit the "#" symbol.
The new entry should have the following format:
IP_Address ihredomain.com www.ihredomain.com
Replace "IP_address" with the actual IP address of the website and "yourdomain.com" with the domain that you associate with the IP.
In our case we connect the non-existent domainmeine-neue-website.comto the IP address35.214.215.226, so the line is:
(Video) How to Edit Hosts File on Your Mac Computer35.214.215.226 meine-neue-website.com www.meine-neue-website.com
To keep the new changes, save the file using the keyboard shortcutStrg + S, or fromfilemenu >Save on computer.
How to edit the hosts file in any macOS version
Step 1.Open Terminal in macOS
You have to use thoseTerminalApplication for editing MachostFile. To open it, navigate toFinder > Go > Utilities.
Open the Utilities menu where Tools for Mac can be accessed. Find theTerminalicon and double-click it.
Alternatively, you can quickly openTerminalby bringing up theSpotlight searchShortcut barCommand + Spacebar. Enter in the pop-up windowTerminaland pressEnter.
Step 2.Open the hosts file in the terminal
Once the terminal window is open, you can edit thehostFile with one of the available text editors.
First, make sure you are in the top-level folder of your Mac by typing the following command:
CD /
PressEnterto confirm the command that will take you to yoursMacintosh-HDmain folder.
The location of the hosts file on Mac computers is:
/private/etc/hosts
In our example we use theNanotext editor. To be able to change the hosts file, you needAdministrator rights (sudo). The command to open the file is:
sudo nano /private/etc/hosts
Once you have confirmed the command withEnter, you will be prompted for the administrator password. Enter the password and confirm withEnter.
Step 3.Edit the hosts file in the terminal
This is where you can add your custom hostname settings. By default, the file contains just a few lines that define the address forpremises HostandBroadcasthost.
Use the arrow keys to move the cursor under the last line where you can add a new entry. To point a domain to a specific server, use the following format:
IP_Address ihredomain.com www.ihredomain.com
You must replaceIP Addresswith the IP of the site andihredomain.comwith the actual domain name.
(Video) How to edit Mac Hosts FileIn our example we want to use the non-existent domainmeine-neue-website.com,which is not registered and has no active DNS settings.
The website formeine-neue-website.comis hosted on the IP address35.214.215.226.
So to force a computer to open this domain from this IP address, you should put the following line in the hosts file:
35.214.215.226 meine-neue-website.com www.meine-neue-website.com
After adding the new settings, press the combinationControl + O(WriteOut) to confirm it, then pressEnter. Finally you can pressStrg + Xto exit the nano editor.
Edit the Linux hosts file
Step 1.Open Terminal on Linux
Just like in macOS, you can edit themhostFile on a Linux operating system from theTerminalApplication. To open the menu with all applications, navigate to the respective button in the lower left corner. Depending on the Linux version, the tool is located on the main page or in theUtilitiesSection. ChooseTerminalicon to open the application.
Step 2.Open the hosts file in the terminal
once insideTerminalIn the console, make sure you are in the top-level folder by typing the following command:
CD /
The way tohostFile on Linux is:
/etc/hosts
Editing the file requires administrator rights (sudo) and a text editor such asNano. Use the following command to open and edit the file:
sudo nano /etc/hosts
The system will prompt you to enter the administrator password before opening the file. After entering the password, pressEnter.
Step 3.Edit the hosts file in the terminal
Use the arrow keys to place the text cursor under the last line written and add the hostname settings. In our case we add an address with the hostnamemeine-neue-website.com. Therefore the line should be:
35.214.215.226 meine-neue-website.com www.meine-neue-website.com
To confirm the new changes, press the key combinationControl + Oand pressEnter.You can then exit the editor by pressingStrg + X.
How can I test changes to the hosts file?
After adding hostname settings, you can test the changes from any web browser like Chrome, Firefox, Opera, Edge, etc. When the changes take effect, the hostname will be resolved from the specified IP address.
The example used so far is the unregistered domainmeine-neue-website.com. It's a nonexistent domain that doesn't have a DNS zone. If the changes don't take effect, you'll see "DNS_PROBE_FINISHED_NXDOMAIN', which is the typical error message for an unregistered domain.

However, if the hostname correctly points to an IP address where a website has been installed, the website will open.

Here's a different way to preview a website
The Hosts file is the most reliable and stable way to preview websites, although there are alternative methods if you find the Hosts file difficult to edit. However, these alternatives have specific strengths and weaknesses and are therefore not suitable for every situation.
We'll explore the other ways to preview a site and the scenarios in which you can use it.
Generate a temporary URL with SkipDNS
A popular way to preview a website is to use a temporary URL. Instead of having to change your hosts file, there are websites that can generate a temporary URL that any computer can use.
This method is only suitable for previewing an existing website. Editing or creating a website with a temporary URL is not recommended because many website applications are domain dependent and new content may be recorded using the temporary URL. This URL will eventually expire, making the content inaccessible.
One of the most popular websites that can generate this type of URL isSkip DNS. On their homepage you will be shown a form to fill out.
You must enter the IP address of the website in the fieldIP Addressand the hostname in the fieldLive-URL. As in our previous example, we want to showmeine-neue-website.comto the IP of the SiteGround hosted website35.214.215.226.

After providing these details, use the buttonCreateto generate the temporary URL. On the next page you will be prompted to agree to the SkipDNS Terms of Service. You will then see the temporary URL SkipDNS generated to open your hostname from the specified IP address.

You can use this URL in any browser or computer to open your website, but remember that this link is only valid for a limited time.

Use a temporary domain with SiteGround
SiteGround users have another option when it comes to accessing a website without a registered domain name – a temporary domain that is automatically generated by the system. It is important to note that a temporary domain can only be set up in your SiteGround account at the time of initial website setup. Once you replace it with another domain, the system will delete the temporary domain.
Therefore, this method is suitable when you start a new website without a registered domain name. It's also useful if you've migrated an existing website but haven't pointed its domain to your account yet and you need to preview the migrated content.
For more information, see this article abouttemporary domains.
summary
The hosts file can come in handy when you want to create a custom hostname mapping just for your computer without affecting other visitors. In general, the most common uses are:
- Linking a non-existent domain to your website
- Force a domain to open a different website than the one it currently points to through DNS records from your computer
- Block access from a computer to a specific hostname
Editing the hosts file might seem daunting at first, but with clear instructions it's not that hard. We hope this article has been able to provide some clarity.
FAQs
How do you edit the hosts file in Linux? ›
- Open a Terminal window.
- Enter the following command to open the hosts file in a text editor: sudo nano /etc/hosts.
- Enter your domain user password.
- Make the necessary changes to the file.
- Press Control-X.
- When you are asked if you want to save your changes, enter y.
- Copy or drag the host file to your machine's desktop.
- Edit the file with notepad or any word processor of your choice.
- Copy or drag the file back to the /system32/drivers/etc folder.
Mac users can find the hosts file in the /private/etc/hosts directory. You can edit it with any text editor as long as you have root user privileges.
How do I edit a host file? ›Click File in the menu bar at the top of Notepad and select Open. Browse the Windows Hosts File location: C:\Windows\System32\Drivers\etc and open the hosts file. Make the needed changes, as shown above, and close Notepad. Save when prompted.
Where is hosts file in Linux? ›The Linux Hosts File's Location
On Linux, you can find the hosts file under /etc/hosts. Since it's a plain text file, you can open the hosts file using your preferred text editor. Since the hosts file is a system file, you'll need administrative rights to save changes.
- Launch Terminal.
- Type sudo nano /etc/hosts and press Return.
- Enter your admin password.
Yes, you can edit the iPad hosts file, but you need to be jailbroken. Once you've done that, download Cydia (app market), and get iFile. The hosts file is located within "/etc/hosts". Save this answer.
Where is the hosts file in Windows? ›In Windows 10 the hosts file is located at c:\Windows\System32\Drivers\etc\hosts. Right click on Notepad in your start menu and select “Run as Administrator”. This is crucial to ensure you can make the required changes to the file. Now click File > Open and browse to : c:\Windows\System32\Drivers\etc\hosts.
What is the hosts file in Linux? ›What is the hosts file in Linux? Simply put, the hosts file is a way to map hostnames to IP addresses. This is very important with certain setups and to make networking on Linux a bit easier. In a sense, the hosts file acts as a local DNS server.
How do I open hosts file in Windows? ›Press Windows Key + R. Type %WinDir%\System32\Drivers\Etc into the Run window and click OK. Open the hosts file with a text editor such as Notepad.
How to edit hosts file Windows 10 command line? ›
- Change the line 127.0. 0.1 localhost to 127.0. ...
- In Notepad, select File then Save to save the file.
- Open a command prompt.
- Type ping me and press Enter.
- Observe the results. ...
- In Notepad, remove me from the line 127.0. ...
- In the command prompt, type ping me and press Enter.
- Observe the results.
The Hosts file on a Mac is found in the /etc/hosts folder.
What is the host name for Mac? ›The local hostname, or local network name, is displayed at the bottom of the Sharing settings window. It identifies your Mac to Bonjour-compatible services. The local hostname is your computer's name with . local added, and any spaces are replaced with hyphens.
How do I edit a file in Mac Terminal? ›In the Terminal app on your Mac, invoke a command-line editor by typing the name of the editor, followed by a space and then the name of the file you want to open. If you want to create a new file, type the editor name, followed by a space and the pathname of the file.
Why edit hosts file Windows? ›Modifying your hosts file enables you to override the domain name system (DNS) for a domain on a specific machine. DNS management is useful when you want to test your site without the test link prior to going live with SSL, verify that an alias site works prior to DNS changes, and for other DNS-related reasons.
How do I add entries to etc hosts in Linux? ›- Open the /etc/hosts file. vi /etc/hosts.
- Add a line of text in the format ip-address localhost localhost. localdomain. As shown in Figure 1, enter 192.168. 1.158 imctest imctest. IMC to map 192.168. 1.158 to the host name imctest in the IMC domain. ...
- Save and close the file.
By default, you cannot edit the hosts file without administrator privileges.
How to edit a file in Linux? ›- Open the file in vim with the command "vim". ...
- Type "/" and then the name of the value you would like to edit and press Enter to search for the value in the file. ...
- Type "i" to enter insert mode.
- Modify the value that you would like to change using the arrow keys on your keyboard.
The hosts file is a plain text file that maps hostnames to IP addresses. It is a part of every major operating system (OS) such as macOS, Windows, Linux, etc.
How to change hostname in Linux? ›Running the hostnamectl command, using nmtui, or editing the hosts file to change the hostname permanently. Using the hostname [new_host_name] command to change the hostname temporarily and without rebooting the system.
How do I open a host file in Linux? ›
- Type the command below, then key in your admin password: sudo su.
- To open the hosts file using Gedit, type the following command and press Enter: sudo gedit /etc/hosts.
The easiest way to edit the hosts file on your device is to use the Android Debug Bridge, so go ahead and set it up. Once you're done, navigate into the folder where ADB is located and type cmd into the location bar, which will open a command prompt in the current folder.
What is host name on iOS? ›Host Name: This is typically your domain name preceded by "mail.". This can be found in the E-mail Accounts section of the cPanel, under More > Configure Mail Client. User Name: Your email address. Password: The password for your email address.
Can you use file Manager on iOS? ›Use the Files app to manage your files on your iPhone, iPad, or iPod touch. On your iPhone, iPad, or iPod touch, you can manage your files in the Files app. When you make changes to your files on one device, your edits are automatically updated on every device using iCloud Drive.
How to edit host file using cmd? ›STEP 1: On your computer, right-click the Start menu, then select the Command Prompt (Admin) option. STEP 2: When the Command Prompt window opens, type the command: cd drivers\etc then press [Enter].
How do I add a host file in Windows? ›- Open your text editor in Administrator mode.
- In the text editor, open C:\Windows\System32\drivers\etc\hosts.
- Add the IP Address and hostname. Example: 171.10.10.5 opm.server.com.
- Save the changes.
The HOST command executes external commands at the operating system level. For a Windows operating system, for example, this is equivalent to running commands from a command prompt in a command window. No output is displayed in a command window.
What is Linux hosting vs Windows hosting? ›Linux uses custom software and supports most programming languages, while Windows uses specific Microsoft software to run and manage data. Linux works on MySQL, while Windows servers use MSSQL. Windows hosting also uses Microsoft ASP.NET as the main programming language.
How do I find my hostname in Linux? ›- Open a terminal. To open a terminal in Ubuntu, select Applications -> Accessories -> Terminal.
- Type hostname at the command line. This will print your computer name on the next line.
Hit the start menu or press the Windows key and start typing Notepad. Right-click Notepad and choose Run as administrator. Now you'll be able to edit and save changes to your HOSTS file.
How do I open hosts file as administrator in Windows 10? ›
- Click Start, click All Programs, click Accessories, right-click Notepad, and then click Run as administrator. ...
- Open the Hosts file or the Lmhosts file, make the necessary changes, and then click Save on the File menu.
To edit the “Hosts” file on Windows 11, open Notepad as an administrator. Use the “Ctrl + O” shortcut and open the Hosts file from the “C:\Windows\System32\Drivers\etc” location. Add a new IP address and domain mapping – for example, 127.0. 0.1 domain.com .
How to change hostname? ›- Check existing hostname. ...
- Modify the value to match your FQDN hostname, as shown in the following example: ...
- Open the file at /etc/hosts. ...
- Change the domain name (where required) ...
- Change networking configuration /etc/sysconfig/network. ...
- Change networking configuration /etc/sysconfig/network.
Get the Hostname From an IP Address on the LAN
When we need to get the hostname of a machine on the same LAN and without a reverse DNS, we can use commands like nmblookup, nbtscan or avahi-resolve. The first two commands are used to lookup NetBIOS names.
First, click on your Start Menu and type cmd in the search box and press enter. A black and white window will open where you will type ipconfig /all and press enter. There is a space between the command ipconfig and the switch of /all. Your ip address will be the IPv4 address.
How do I open and edit a file in Linux Terminal? ›- There are several different tools within Linux that can be used to edit files. ...
- To open a file in Nano, you must enter the nano command followed by the path of the file you are attempting to open. ...
- The other popular option for editing a file in Linux is to use the vi command.
- Just type micro to create and edit a new text file.
- Type micro <filename> to start editing an already-made file.
- To save: ctrl + s.
- To see a list of keybindings: alt + g.
- To quit: ctrl + q.
- You can also double-click the Terminal icon in your list of Applications, or by clicking your Dash menu (if you're using GNOME) and searching for terminal .
- Nano is a very easy-to-use text editor that comes preinstalled on all Ubuntu-based Linux distributions.
- Open your text editor in Administrator mode.
- In the text editor, open C:\Windows\System32\drivers\etc\hosts.
- Add the IP Address and hostname. Example: 171.10.10.5 opm.server.com.
- Save the changes.
- Step 1: Open the Mac Terminal. Open the Finder, and go to Applications > Utilities > Terminal. Type the following in the terminal window: sudo nano /private/etc/hosts. ...
- Step 2: Edit Mac Hosts File. The IP address is first, and the server name comes second. Comments are indicated with a '#' sign.
Does Linux have a hosts file? ›
The hosts file is a plain text file that maps hostnames to IP addresses. It is a part of every major operating system (OS) such as macOS, Windows, Linux, etc.
What is ETC hosts file in Linux? ›The /etc/hosts file contains the Internet Protocol (IP) host names and addresses for the local host and other hosts in the Internet network. This file is used to resolve a name into an address (that is, to translate a host name into its Internet address).
What is the edit command in Linux? ›edit makes a copy of the file FILENAME which you can then edit. It first tells you how many lines and characters are in the file. If the file does not exist, edit tells you it is a [New File]. The edit command prompt is a colon (:), which is shown after starting the editor.
How to edit a file in Linux from command-line? ›- Open the file using the vi or vim command: vi example_file.
- Press the "i" key to enter insert mode.
- Make your desired changes. ...
- Press the escape "ESC" key to exit insert mode.
- Type ":w" and press the enter key to save your changes.
- Type ":q" and press the enter key to close the file.
- Log into your server via SSH.
- Navigate to the directory location you wish to create the file in or edit an existing file.
- Type in vim followed by the name of the file. ...
- Press the letter i on your keyboard to enter INSERT mode in vim. ...
- Start typing into the file.
host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy.
How do I change the hostname and domain name in Linux? ›- Check existing hostname. ...
- Modify the value to match your FQDN hostname, as shown in the following example: ...
- Open the file at /etc/hosts. ...
- Change the domain name (where required) ...
- Change networking configuration /etc/sysconfig/network. ...
- Change networking configuration /etc/sysconfig/network.
To change your IP address on Linux, use the “ifconfig” command followed by the name of your network interface and the new IP address to be changed on your computer. To assign the subnet mask, you can either add a “netmask” clause followed by the subnet mask or use the CIDR notation directly.
How do I access host files? ›- Open the Start menu.
- In the Run box, type Notepad.exe and press Enter. ...
- In Notepad, select File then Open.
- Navigate to C:\Windows\System32\drivers\etc.
- Change the file type to open from Text Documents (*. ...
- Open the hosts file.
- Read the comments in the host file.
In Windows 10 the hosts file is located at c:\Windows\System32\Drivers\etc\hosts. Right click on Notepad in your start menu and select “Run as Administrator”. This is crucial to ensure you can make the required changes to the file. Now click File > Open and browse to : c:\Windows\System32\Drivers\etc\hosts.
Where can I find host entries? ›
To open the hosts file in Notepad, click "File", "Open", and navigate to C:\Windows\System32\drivers\etc . You'll see a file named hosts . Double click on that file to open it.