Test an application through the hosts file
Map your domain to an Azion IP address in your device's hosts file to open an application on that domain before you change its DNS records.
You can open an application on your own domain from one device before you change the DNS records of the domain. The hosts file of that device sends the domain to Azion, while every other visitor still reaches your current provider. To run an application on your own machine instead, use the Azion CLI.
Prerequisites
- An application that a workload serves. To create one and serve it, refer to Applications quickstart.
- Your domain, added to the domains of that workload. For more information, refer to Workloads.
- Administrator rights on your device. Linux and macOS grant them through
sudo. - A terminal, such as Windows PowerShell or Terminal on macOS.
- On Windows, a text editor, such as Notepad.
- An internet connection.
Look up the IP addresses of your workload domain
Your workload domain is the azionedge.net address that Azion assigns to the workload. It resolves to Azion IP addresses that depend on where the device is. Run the lookup on the device you test from.
Run a DNS lookup tool, such as host, with your workload domain in place of <your-workload-domain>:
The command prints a has address line for each IP address that the workload domain resolves to. Copy one of these addresses.
Map your domain to the IP address
The hosts file maps names to IP addresses on one device. Add one line for each domain you want to test: the IP address you copied, one or more spaces, then the domain. Map only a domain that you added to the workload.
For example, these lines send example.com and www.example.com to the address 192.0.2.10:
The file ignores the text after a # on a line. A comment such as # Azion test marks the lines you add, so you can find them when you finish.
The location of the file and the editor depend on the operating system of your device.
Edit the hosts file on Windows
On Windows, the hosts file is in C:\Windows\System32\drivers\etc\. When Windows is installed on another drive, the same folder is on that drive.
To edit the file on Windows:
Open Notepad, or another text editor, with your administrator rights.
Open hosts from the etc folder.
Add your lines after the localhost line.
Select File > Save.
The hosts file holds your lines, and Windows resolves each domain in them to the IP address you entered.
Edit the hosts file on Linux
On Linux, the file is /etc/hosts. To edit it with the vim editor:
In most distributions, the terminal is in Applications > Utilities > Terminal.
Run this command:
Enter your system password and press Enter. The file opens in vim.
With the arrow keys, move to the line after localhost. Press i to start typing, then add your lines.
Press Esc.
Type :x and press Enter.
vim saves /etc/hosts and closes, and Linux resolves each domain in your lines to the IP address you entered.
Edit the hosts file on macOS
On macOS, the file is /private/etc/hosts. To edit it with the nano editor:
In Launchpad, search for Terminal and open it.
Run this command:
Enter your system password and press Enter. The file opens in nano.
With the arrow keys, move to the line after localhost, then add your lines.
Press Ctrl+O, then press Enter to keep the file name.
Press Ctrl+X.
nano saves /private/etc/hosts and closes, and macOS resolves each domain in your lines to the IP address you entered.
Open the application on your domain
With the hosts file saved, requests from your device to the mapped domains go to Azion. This holds even while the public DNS records of the domain still point to your current provider.
A browser can keep a DNS cache of its own. If it already visited your domain, it can reuse the public address it cached and skip the hosts file. To open the domain without that cache, use one of these:
- A private or incognito window.
- A browser that you did not use to visit the domain.
- Your usual browser, after you clear its cache.
Then enter your domain in the address bar. The browser shows the application that your workload serves.
Test the application before you change the public DNS of the domain. Then point its DNS records to Azion, or move its nameservers to Edge DNS. When you finish, delete the lines you added, so the device resolves the domain through public DNS again.