Den här artikeln finns även på: Svenska
To locally point a domain using a hosts file makes it very easy to test a website you’ve built on another server without affecting general access to the current website.
If the website you’re building is using a CMS such as WordPress or Magento, you will not have to go through the hassle of changing the URL the site is using. If you on the other hand use a temporary domain, you’ll need to update all URLs on the site once you’re ready to go live.
Below, we describe how you point a domain locally in the most commonly used operating systems.
Windows 7, 8, and 10
- Open Notepad as administrator: In Windows 8 and 10, press the
Windowskey on your keyboard and start typing
Notepadto find the program. In Windows 7, use the search field under the Start menu to find it. Either way, right-click the program and click
Run as Administrator.
- Open the hosts file in the program via
Open. In the filename field, enter
- You will now see number of comment lines (starting with #). Add an IP address and the domain you want to point at the bottom of the file. If the domain is to be pointed towards a web hosting account on our servers, you can find the correct IP address via these instructions. Below follows examples of such rows:
220.127.116.11 exempel.se 18.104.22.168 www.exempel.se
- Don’t forget to save the hosts file ones you’re done editing it! If the program tells you you cannot save, make sure that you started Notepad as administrator.
MacOS 10.6+ and Linux/Unix
- Begin by opening a terminal:
- On macOS, press
spaceon your keyboard and type
terminal, and press
Enter. You can also find the app
Utilitiesfolder in your
Applicationsfolder, if you rather click your way to the app.
- If you’re using Linux/Unix, start your favourite terminal. Which ones you have access to vary depending on your distribution.
- On macOS, press
- Open the hosts file with a text editor as the root user, e.g. with the command
sudo nano /etc/hosts. Keep in mind that your user must have sudo permissions on Linux/Unix for this to work. If you run macOS, your user needs to be administrator.
- Add the IP address and the domain on a new line at the end of the file (in the same way as displayed in the Windows example above), and save it. If you use nano, you can save by pressing
Xon your keyboard and confirm that you want to save with the