What is the Hosts File?

The hosts file is a simple text file that maps hostnames to IP addresses. It acts as a local DNS override, allowing you to redirect domain names to specific IP addresses before your system queries external DNS servers.

Location by Operating System

  • Linux/macOS: /etc/hosts
  • Windows: C:WindowsSystem32driversetchosts

Basic Syntax

# Comments start with hash
127.0.0.1    localhost
192.168.1.100    nextcloud.local
192.168.1.100    stash.local
192.168.1.100    metube.local

Practical Example: MCT Services

Here is how we configure local access to our MCT services:

# MCT Personal Cloud Services
127.0.0.1    nextcloud.mct.local
127.0.0.1    stash.mct.local  
127.0.0.1    metube.mct.local
127.0.0.1    dashy.mct.local
127.0.0.1    pihole.mct.local

Why Use Custom Domains?

  • Professional URLs: nextcloud.local vs localhost:8080
  • SSL Certificate Support: Proper domain names for HTTPS
  • Service Organization: Logical grouping of services
  • Port Management: Hide complex port configurations

Hands-On Exercise

Task: Configure your hosts file for local development

  1. Open your hosts file with administrator/sudo privileges
  2. Add entries for our MCT services
  3. Test resolution with ping nextcloud.mct.local
  4. Verify with nslookup nextcloud.mct.local

Common Issues and Solutions

  • Permission Denied: Use sudo/administrator privileges
  • Changes Not Taking Effect: Clear DNS cache
  • Syntax Errors: Check for proper spacing and formatting

DNS Cache Clearing Commands

# Linux
sudo systemctl restart systemd-resolved

# macOS  
sudo dscacheutil -flushcache

# Windows
ipconfig /flushdns
Last modified: Thursday, 6 November 2025, 8:47 AM