The /etc/hosts
file is a local DNS resolver that maps hostnames to IP addresses before querying external DNS servers. Each entry follows this format:
IP_address hostname [alias1] [alias2] ...
For your specific case wanting to resolve multiple domains to 81.174.66.48
, the proper format would be:
81.174.66.48 nerto.it nerto eventlog.it eventlog.in
Or alternatively as separate entries (though less efficient):
81.174.66.48 nerto.it nerto
81.174.66.48 eventlog.it
81.174.66.48 eventlog.in
After editing, verify the changes using these commands:
ping nerto.it
ping eventlog.in
host eventlog.it
nslookup nerto
Remember to clear your DNS cache if needed:
# Linux
sudo systemd-resolve --flush-caches
# macOS
sudo dscacheutil -flushcache
# Windows
ipconfig /flushdns
For testing multiple environments, you might want to create backup versions:
# Create backup
sudo cp /etc/hosts /etc/hosts.bak
# Restore if needed
sudo cp /etc/hosts.bak /etc/hosts
For complex setups, consider using wildcard DNS locally with dnsmasq
:
# Install dnsmasq
sudo apt install dnsmasq
# Configure
echo "address=/it/81.174.66.48" | sudo tee -a /etc/dnsmasq.conf
sudo systemctl restart dnsmasq
The /etc/hosts
file follows a specific format where each line contains:
IP_address hostname1 hostname2 ...
For your case with IP 81.174.66.48
and domains nerto.it
, eventlog.it
, etc., the correct syntax would be:
81.174.66.48 nerto.it nerto eventlog.it eventlog.in
The issue with your initial attempt was splitting the domains across multiple lines for the same IP. The proper way is to list all hostnames on a single line with the IP address.
Example of incorrect approach:
# This won't work as expected
81.174.66.48 nerto.it nerto
81.174.66.48 eventlog.it
81.174.66.48 eventlog.in
After modifying /etc/hosts
, test with:
ping nerto.it
ping eventlog.in
dig +short eventlog.it
For developers needing more complex setups:
# Local development with multiple domains
127.0.0.1 localhost myapp.dev api.myapp.dev admin.myapp.dev
Remember that modern systems typically check DNS before /etc/hosts
. To prioritize local resolution:
# In /etc/nsswitch.conf (Linux)
hosts: files dns
Windows equivalent (C:\Windows\System32\drivers\etc\hosts
):
81.174.66.48 nerto.it
81.174.66.48 eventlog.it
81.174.66.48 eventlog.in
Note Windows requires separate lines per hostname.