>_ IzzyLab

Hands-on task

This task is step 7 of the course “Networking: first steps”

What address a name has

easy~4 min

The office services are reached by names like git.office.lan, not by IP addresses. Find out which IP address the name billing.office.lan turns into on this machine and write the address to /root/billing_ip.txt — just the address.

What you'll practise:
  • getent hosts
  • /etc/hosts
  • names and addresses

Topic breakdown

People prefer names (git.office.lan), but the network needs IP addresses. Turning a name into an address is called name resolution (resolving). Where to look is set in /etc/nsswitch.conf; usually it has the line hosts: files dns — first the /etc/hosts file, then a DNS server.

/etc/hosts is a simple "address — names" table:

127.0.0.1    localhost
10.1.0.7     db.example.lan  db     # one address can have several names
# 10.1.0.3   old.example.lan        # a line with # is a comment and has no effect

The easiest way to find out which address a program will get is getent hosts — it goes the same way as curl, ping and the rest:

$ getent hosts localhost
127.0.0.1       localhost

There's also dig, a DNS tool. It asks only the DNS server and doesn't read /etc/hosts, so it won't find names from that file. That's why dig billing.office.lan will say there's no such name, even though curl and getent find it.

What's checked

  1. File /root/billing_ip.txt created
  2. The file holds only an IP address
  3. It's the address the system gives for billing.office.lan

What it looks like