As a Linux system administrator working with mixed environments, I've often found myself caught between two different schools of thought regarding hostname configuration. The Red Hat/CentOS camp advocates for using Fully Qualified Domain Names (FQDNs) in the /etc/sysconfig/network
file:
# RHEL/CentOS style HOSTNAME=server01.example.com
Meanwhile, Debian/Ubuntu systems explicitly recommend against FQDNs in /etc/hostname
:
# Debian/Ubuntu style server01
This divergence becomes particularly important when dealing with automation tools and monitoring systems. For example, Nagios might behave differently depending on how the hostname is set:
# Bash script checking hostname type if [[ $(hostname) == *.* ]]; then echo "FQDN detected - compatible with RHEL-based monitoring" else echo "Short name detected - may require configuration adjustments" fi
When managing mixed environments, I recommend choosing one approach and applying it consistently. Here's a Puppet manifest snippet that enforces consistency:
# Puppet code to standardize hostnames case $::osfamily { 'RedHat': { file_line { 'set FQDN hostname': path => '/etc/sysconfig/network', line => "HOSTNAME=${::fqdn}", } } 'Debian': { file { '/etc/hostname': content => "${::hostname}\n", } } } exec { 'apply hostname': command => "/bin/hostname ${::hostname}", }
Some enterprise software has specific requirements:
- Oracle RAC: Prefers FQDNs for node identification
- IBM Tivoli: Some components require short names
- Kubernetes: Uses FQDNs for node registration
For most modern environments, I suggest using FQDNs as they provide clearer identification in distributed systems. Here's how to convert a short name to FQDN in a script:
#!/bin/bash # Ensure FQDN is set SHORT_NAME=$(hostname -s) DOMAIN=$(dnsdomainname) FQDN="${SHORT_NAME}.${DOMAIN}" # Apply to RHEL systems if [ -f /etc/redhat-release ]; then sed -i "s/HOSTNAME=.*/HOSTNAME=${FQDN}/" /etc/sysconfig/network hostname "$FQDN" fi
In Linux system administration, one of the most persistent debates revolves around whether to configure the system hostname as a Fully Qualified Domain Name (FQDN) or just the short hostname. Major distributions like Red Hat/CentOS and Debian/Ubuntu have fundamentally different recommendations:
# Red Hat/CentOS style (typically in /etc/sysconfig/network)
HOSTNAME=server1.example.com
# Debian/Ubuntu style (in /etc/hostname)
server1
Red Hat/CentOS: Explicitly recommends using FQDN in their documentation. The /etc/sysconfig/network
file expects the full domain name.
Debian/Ubuntu: The /etc/hostname
file should contain only the short hostname, with the domain configured separately in /etc/hosts
or via DHCP.
Several system components behave differently based on hostname configuration:
- Postfix: Uses the system hostname for HELO/EHLO unless explicitly configured
- Apache: ServerName directive may inherit from system hostname
- SSH: Host keys are stored using the reported hostname
For mixed environments, I recommend this hybrid approach:
# /etc/hostname (short name)
server1
# /etc/hosts configuration
127.0.0.1 localhost
192.168.1.10 server1.example.com server1
# Additional configuration for Red Hat systems
if [ -f /etc/sysconfig/network ]; then
echo "HOSTNAME=server1.example.com" >> /etc/sysconfig/network
fi
These commands help manage hostnames consistently:
# Set transient hostname (until reboot)
hostnamectl set-hostname server1
# Set pretty hostname (for display purposes)
hostnamectl set-hostname --pretty "Production Web Server"
# View current settings
hostnamectl status
When hostname configuration causes problems:
- Check what
hostname -f
returns (should be FQDN) - Verify
getent hosts $(hostname)
resolves correctly - Ensure reverse DNS matches forward DNS
The most robust approach is to configure both short name and FQDN properly in all relevant locations, then test all critical services.