ping and every other program look a name up in /etc/hosts first, and ask DNS only if it isn't there. dig skips the file: it only ever asks DNS. So they can disagree.
New command
getent hosts
Looks a name up the way programs do: /etc/hosts, then DNS. Prints nothing when the name isn't found, or DNS didn't answer: check with dig.
Usagegetent hosts name
text
learner@ops:~$ getent hosts shop.monster.market
10.0.0.10 shop.monster.marketA stale line in /etc/hosts beats the right answer in DNS, for every program on that machine. To delete a line, open the file in the editor as root:
bash
sudo nano /etc/hostsObjectives
- What address do programs on ops get?
- Remove the stale line.