My question addresses a strange behaviour of hostname -f on my Gentoo Linux System.
The symptom:
rt01 ~ # time hostname -f
rt01.domain.net
real 0m5.007s
user 0m0.001s
sys 0m0.000s
With strace i can see that the following steps are performed:
- Read /etc/host.conf (probably) to determine the order of how host lookups should be done
- Read /etc/hosts (in my opinion this should be enough, instead it is ...)
- Connecting to the DNS server specified in /etc/resolv.conf
- Read /etc/hosts again
The iptables setup on that machine prevents it from connecting to any DNS server. So it is - by design - blocked at this point. My expectation is, that this step would not be necessary with the following configuration:
/etc/host.conf
# This keyword specifies how host lookups are to be performed. It
# should be followed by one or more lookup methods, separated by
# commas. Valid methods are bind, hosts, and nis.
#
order hosts, bind
/etc/hosts
# IPv4 and IPv6 localhost aliases
127.0.0.1 rt01.domain.net rt01 localhost
<public ip> rt01.domain.net rt01
::1 localhost
/etc/conf.d/hostname
# Set to the hostname of this machine
hostname="rt01"
Can somebody explain to me, why hostname -f tries to connect to a DNS Server. I thought the information provided by /etc/hosts should be enough.