Jun 22, 2026
How to Set Up DNS for Multiple Websites on One Server
Many businesses host multiple websites on a single server to save costs and simplify management. But how does DNS know which website to serve when someone visits one of your domains?
The answer is virtual hosting β a technique that allows a single server to host multiple websites, each with its own domain name. DNS plays a crucial role in making this work.
In this guide, we'll explain how to set up DNS for multiple websites on one server.
Back to Blog
How Virtual Hosting Works
When a visitor types your domain name, DNS translates it to your server's IP address. But since multiple websites share that same IP address, the server needs to know which site to serve. The server uses the Host header β the domain name in the request β to determine which website to display. This is called name-based virtual hosting. Here's the flow:- Visitor types example.com into their browser.
- DNS resolves example.com to your server's IP address (e.g., 192.168.1.100).
- Browser sends a request to 192.168.1.100 with the Host header set to example.com.
- Server looks at the Host header and serves the correct website.
Step-by-Step DNS Setup
Here's how to configure DNS for multiple websites:Step 1: Point Each Domain to Your Server
For each domain you want to host, create an A record that points to your server's IP address:- domain1.com: A record β 192.168.1.100
- domain2.com: A record β 192.168.1.100
- domain3.com: A record β 192.168.1.100
Step 2: Set Up www Records
Don't forget the www subdomain. Create CNAME records or additional A records:- www.domain1.com: CNAME β domain1.com
- www.domain2.com: CNAME β domain2.com
- www.domain3.com: CNAME β domain3.com
Step 3: Configure Your Web Server
Your web server (Apache or Nginx) needs to be configured to recognize each domain: Apache (Virtual Hosts):
<VirtualHost *:80>
ServerName domain1.com
DocumentRoot /var/www/domain1
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
DocumentRoot /var/www/domain2
</VirtualHost>
Nginx (Server Blocks):
server {
listen 80;
server_name domain1.com;
root /var/www/domain1;
}
server {
listen 80;
server_name domain2.com;
root /var/www/domain2;
}
Step 4: Set Up Email Records
For each domain, configure MX records for email:- domain1.com: MX β mail.domain1.com
- domain2.com: MX β mail.domain2.com
Step 5: Test Your Setup
Verify everything works:-
li>Visit each domain in a browser β they should load the correct website.
li>Check DNS propagation using tools like dnschecker.org.
- Test email delivery for each domain.
Common Mistakes to Avoid
Here are pitfalls to watch out for:-
li>Forgetting www records: Always set up both the bare domain and www subdomain.
- DNS propagation delays: Changes can take up to 48 hours to propagate worldwide.
- Missing virtual host configurations: If the server doesn't recognize a domain, visitors see the wrong site or an error.
- SSL certificate issues: Each domain needs its own SSL certificate. Use a multi-domain certificate or individual certificates.
Managing Multiple Domains Efficiently
Here are tips for managing multiple websites:-
li>Use a DNS management tool: Many registrars and DNS providers offer dashboards for managing multiple domains.
- Automate DNS updates: Use APIs or scripts to update DNS records programmatically.
- Keep documentation: Maintain a list of all domains, their DNS records, and server configurations. li>Use consistent naming: Follow a consistent pattern for directory structures and configurations.