With hostnamectl
RHEL 8 has multiple documents: Product Documentation for Red Hat Enterprise Linux 8 | Red Hat Customer Portal
@gerry666uk did point to the “How to use the Anaconda installer” piece. That is for initial installation. Even there are both interactive and automated (kickstart) methods. The interactive ask for values and choices and does then install. In kickstart user supplies the pre-made values and choices via a “kickstart-file”.
That is for the initial install. When you have a system and want to set hostname, methods are different.
Strangely, “A guide to configuring and managing networking in Red Hat Enterprise Linux 8” does not mention hostnamectl, while “Configuring and managing networks, network interfaces, and network services in RHEL 7” did.
The RH documentation is available as Single-page and Multi-page HTML, PDF, and ePub. Yes, the behaviour of TOC-pane in HTML versions is most inconvenient. Perhaps PDF ond ePub viewers are more comfy?
Most of the time I don’t set hostname at all – transient hostname is received from DHCP server.
Btw, for small network I do prefer dnsmasq
as it can act as DHCP server, DNS server, and as TFTP server for PXEboot. Furthermore, rather than running separate dnsmasq.service
, I have the NetworkManager.service
start an instance. While that instance is primarily a caching DNS relay (as the default glibc resolver is “awful”), it can be customized to act as DHCP and authoritative DNS too.
How to make NM use dnsmasq: Chapter 31 in Configuring and managing networking Red Hat Enterprise Linux 8 | Red Hat Customer Portal
How to customize that instance … NM starts dnsmasq with some options. Some you can override, some work around. I have copy of configs somewhere and deploy with Ansible tasks:
- name: Get service facts
service_facts:
- name: Install dnsmasq
yum:
name: dnsmasq
state: present
when:
- ansible_facts.services["NetworkManager.service"] is defined
- ansible_facts.services["NetworkManager.service"].state == "running"
- name: Set NetworkManager to use dns=dnsmasq
copy:
src: 00-dns.conf
dest: /etc/NetworkManager/conf.d/00-dns.conf
when:
- ansible_facts.services["NetworkManager.service"] is defined
- ansible_facts.services["NetworkManager.service"].state == "running"
notify: Restart NetworkManager
- name: Add config for dnsmasq in server
copy:
src: "{{ dnsmasq_conf }}"
dest: "/etc/NetworkManager/dnsmasq.d/{{ dnsmasq_conf }}"
when:
- ansible_facts.services["NetworkManager.service"] is defined
- ansible_facts.services["NetworkManager.service"].state == "running"
- dnsmasq_conf is defined and dnsmasq_conf|length > 0
notify: Restart NetworkManager
- name: Add hosts for dnsmasq in server
copy:
src: "{{ dnsmasq_hosts }}"
dest: "/etc/{{ dnsmasq_hosts }}"
when:
- ansible_facts.services["NetworkManager.service"] is defined
- ansible_facts.services["NetworkManager.service"].state == "running"
- dnsmasq_hosts is defined and dnsmasq_hosts|length > 0
notify: Restart NetworkManager
with 00-dns.conf
:
# Ansible managed #
[main]
dns=dnsmasq
The dnsmasq_conf starts:
# Ansible managed #
domain-needed
bogus-priv
expand-hosts
domain=admin,10.0.0.0/24,local
interface=admin
listen-address=10.0.0.1
addn-hosts=/etc/ourhosts
# DHCP pool setup
dhcp-range=set:admin,10.0.0.200,10.0.0.240,12h
dhcp-option=tag:admin,option:router,10.0.0.1