>_ IzzyLab

Hands-on task

This task is step 9 of the course “New server: setup from scratch”

A site name before DNS

easy~2 min

The shop's DNS records will only be created tomorrow, but the site has to be tested on the server today. Make the names shop.local and www.shop.local resolve to 127.0.0.1 on this machine — locally, without a DNS server. The localhost entry must stay.

What you'll practise:
  • /etc/hosts
  • name resolution
  • getent
  • nsswitch
  • loopback

Topic breakdown

Before going to DNS, the system looks into /etc/hosts — a simple "IP → names" table; the order of sources is set by the hosts: line in /etc/nsswitch.conf. That's handy while there are no real DNS records yet: you can pin the site's name to an address right on the machine. The line format is an address followed by one or more names separated by spaces; 127.0.0.1 is loopback, i.e. the machine itself. Note that dig goes straight to DNS and doesn't see /etc/hosts, while getent hosts asks the resolver the same way ordinary programs do.

What's checked

  1. shop.local resolves to 127.0.0.1
  2. www.shop.local resolves to 127.0.0.1
  3. the localhost entry is in place

What it looks like