Network Configuration Files
Linux name resolution relies on three key files:
/etc/hosts,/etc/resolv.conf, and/etc/nsswitch.conf.Together, they define where and in what order to look for hostname information.
1. /etc/hosts
- Contains a table of hostnames and their IP addresses.
- Can supplement DNS for name resolution.
- Example:
/etc/nsswitch.conf prioritizes files.
2. /etc/resolv.conf
- Stores DNS server IP addresses for hostname resolution.
- Can include additional keywords like
domainandsearch. - Example:
- Tries the first nameserver.
- If unavailable or timeout, tries the second nameserver.
-
Keywords:
domain: Appends the domain for partial hostnames (e.g.,polaris→polaris.snowblower.example.com).search: Lists multiple domains to try in order for name resolution.
3. /etc/nsswitch.conf
- Configures the order of hostname lookup sources.
- Example entry:
files→/etc/hostsis checked first.dns→ DNS server(s) in/etc/resolv.confare used second.-
Order affects resolution behavior:
-
If a hostname is found in
/etc/hosts, DNS may not be used, even if the IP is incorrect.
Name Resolution Flow
- System consults
/etc/nsswitch.confto determine lookup order. - Checks
/etc/hostsfor a matching entry. - If no match, queries the DNS server(s) listed in
/etc/resolv.conf. - Result is cached for a configurable period.