Comments 5 Posted In Red Hat Enterprise Linux Tags network Resolve Hostname to FQHN Latest response 2016-07-11T11:00:10+00:00 In /etc/host the fully qualified name is there and but in /etc/sysconfig/network the short name is there instead of the fully qualified domain name. How would I get hostname -f to get it to display FQHN? Ed Started 2016-02-03T19:29:05+00:00 by Edward_Treas Newbie 5 points Log in to join the conversation Responses Sort By Oldest Sort By Newest Guru 1940 points 9 July 2016 9:34 AM Jörg Kastning Hello Edward, In my /etc/hosts is the localhost present only. My /etc/sysconfig/network is empty. On my RHEL 7 the hostname (test1) ist stored in /etc/hostname and the domain is configured in /etc/sysconfig/network-scripts/ifcfg-ens192 like: DOMAIN="example.com" With this configuration "hostname -f" displays the fqdn test1.example.com. Kind regards, Joerg SM Guru 6155 points 10 July 2016 12:45 PM Sadashiva Murthy M The hostname entries in /etc/hosts are for local name resolution and system read hostname from here when /etc/nsswitch.conf is set to read from here. Also, when there is no dns involved the name set in /etc/sysconfig/network doesn't have any significance. hostname man page says this... The function gethostname(2) is used to get the hostname. When the hostname -a, -d, -f or -i is called will gethostbyname(3) be called. The difference in gethostname(2) and gethostbyname(3) is that gethost- byname(3) is network aware, so it consults /etc/nsswitch.conf and /etc/host.conf to decide whether to read information in /etc/syscon- fig/network or /etc/hosts SW Red Hat Guru 4497 points 11 July 2016 7:26 AM Stephen Wadeley Hello, there is also the Configure Host Names chapter in the Red Hat Enterprise Linux 7 Networking Guide. SM Guru 6155 points 11 July 2016 8:48 AM Sadashiva Murthy M For testing purpose, I changed the hostname entry (rhel 6 vm) in /etc/sysconfig/network with static IP configuration set, and there is no DNS involved and 'NetworkManager' turned off . I had put both fqdn and alias entries in /etc/hosts file and my /etc/nsswitch.conf file is set as : <br />[root@server222 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.100 server1.example.com server1 192.168.1.200 server2.example.com server2 [root@server222 ~]# grep -i host /etc/nsswitch.conf #hosts: db files nisplus nis dns hosts: files dns [root@server222 ~]# cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=server222 NOZEROCONF=yes ARPCHECK=no GATEWAY=192.168.1.254 [root@server222 ~]# sysctl -a|grep hostname kernel.hostname = server222 [root@server222 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO="static" HWADDR="00:0c:29:43:98:f6" ONBOOT="yes" TYPE="Ethernet" IPADDR="192.168.1.100" NETMASK="255.255.255.0" Strangely, hostname got changed to "server222" which says that it has red it from /etc/sysconfig/network file and when I run "hostname -f" it failed even after I changed hostname entry and restarted network service : [root@server222 ~]# grep -i hostname /etc/sysconfig/network HOSTNAME=server1 [root@server222 ~]# hostname -f -v gethostname()=`server222' Resolving `server222' ... hostname: Host name lookup failure So, this confirms that the function gethostname() is actually reading from kernel.hostname entry, hence, I changed kernel entry after which (hostname -f)it worked successful: [root@server222 ~]# sysctl -n kernel.hostname server222 [root@server222 ~]# sysctl -w kernel.hostname=server1 kernel.hostname = server1 [root@server222 ~]# sysctl -n kernel.hostname server1 [root@server222 ~]# hostname -f -v gethostname()=`server1' Resolving `server1' ... Result: h_name=`server1.example.com' Result: h_aliases=`server1' Result: h_addr_list=`192.168.1.100' server1.example.com The hostname entry in /etc/sysconfig/network should be the FQDN as per this Red Hat KB : What all options are available in /etc/sysconfig/network file in Red Hat Enterprise Linux 6? There is another KB which is marked as "unverified": Hostname is incorrect with hostname and hostname -f which has to be corrected by Red Hat, otherwise, remove this mis-leading KB. SW Red Hat Guru 4497 points 11 July 2016 11:00 AM Stephen Wadeley Hello, I will get those KBase solutions reviewed. The Red Hat Enterprise Linux 6 Deployment Guide had this section added recently Setting the Host Name.