Best Practices for Setting Hostname in VPS: example.com vs www.example.com vs bare domain for Debian Server Configuration


2 views

When configuring a new Debian VPS, the hostname decision impacts multiple system components including mail services, SSL certificates, and system logging. For domain example.com, you have three logical options:


1. example.com (Fully Qualified Domain Name - FQDN)
2. www.example.com (subdomain FQDN)  
3. example (short hostname)

FQDN (example.com): The most comprehensive approach. Required for:

  • Proper SSL certificate validation
  • Email server configurations (Postfix/Exim)
  • Reverse DNS lookups

Subdomain (www.example.com): Only recommended if:


# When checking with hostname command:
$ hostname -f
www.example.com

This might cause issues with non-www services like mail.example.com

For Debian 8.7 Jessie, edit these files:


# /etc/hostname should contain either:
example.com
# OR
example

# /etc/hosts requires matching entry:
127.0.1.1 example.com example

When using virtual hosts, the ServerName directive should match:



    ServerName example.com
    ServerAlias www.example.com
    # ... other directives

Modern certificates (Let's Encrypt) validate FQDN:


# Certbot command for proper FQDN:
sudo certbot --apache -d example.com -d www.example.com

On modern Debian systems using systemd:


# To permanently set FQDN:
hostnamectl set-hostname example.com

Verify your configuration with:


hostname -f  # Should return FQDN
hostname -s  # Should return short name

Mismatches here often cause mail delivery problems.


When configuring a new VPS running Debian (or any Linux distribution), the hostname serves as the unique identifier for your server within the network. The hostname is used by various system components including mail services, logging systems, and SSH prompts.

For a domain like example.com, you have three common options:

1. example.com (Fully Qualified Domain Name - FQDN)
2. www.example.com (Subdomain FQDN)
3. example (Short hostname)

The most widely accepted practice is to use the short hostname (example) for the system hostname, while configuring the FQDN in other services as needed. Here's why:

  • Prevents potential DNS resolution issues during boot
  • Keeps system logs cleaner
  • Maintains flexibility for server role changes

To set the hostname in Debian 8.7 Jessie:

# Set hostname temporarily
hostname example

# Set hostname permanently in /etc/hostname
echo "example" > /etc/hostname

# Update /etc/hosts
127.0.0.1   localhost
127.0.1.1   example.example.com  example

Check your configuration with these commands:

hostname           # Shows short hostname
hostname -f        # Shows FQDN
hostname -A        # Shows all FQDNs
cat /etc/hostname  # Shows persistent hostname

For servers running multiple services, consider these patterns:

# Web server
hostname web01

# Database server  
hostname db01

# Mail server
hostname mail

Remember to update DNS records separately to point your domain to the server's IP address.