Names
Contents
Naming Conventions are necessary in IT-Business.
Usernames and Groupnames
Links
Name conventions
Only lowercase [a-z]
- Minimum 1 letter in local part
No starting, trailing [.-]
System user- and group-names may start with an underscore _
Must obey /etc/adduser.conf
- Domain-part may exist
Domain-delimiter "@"
Minimum 1 letter in domain after "@"
Local-part may contain [a-z0-9_-$]
Compatibility to Samba with trailing "$" in username Microsoft Support - compatibility with user accounts ending with the dollar sign
Domain-part may contain [a-z0-9-.]
Periods "." only in domain-part
Standards for user and group names
POSIX Standards
REGEX for user and group names
PCRE grep -P
1 ^_?[a-z0-9]([a-z0-9_-]*[a-z0-9])?\$?(\@(([a-z0-9]([-a-z0-9]*[a-z0-9])?\.?)+)([a-z0-9]([-a-z0-9]*[a-z0-9])))?$
Tested against this file
1 -invaliduser
2 -invalid_user
3 -invalid-user
4 .invaliduser
5 invalid_user_
6 invalid_user-
7 invalid_user.
8 invalid-user_
9 invalid-user-
10 invalid-user.
11 invalid.user
12 invaliduser_
13 invaliduser-
14 invalid_user@subdomain.2ld-.tld
15 invalid_user@subdomain.2ld.-tld
16 invalid_user@subdomain.2ld.-tld.
17 invalid-user@subdomain._2ld-.tld
18 invalid-user@subdomain._2ld.tld
19 invaliduser@-subdomain-.2ld.tld.
20 invaliduser@-subdomain.2ld.tld
21 invaliduser@-subdomain.2ld.tld.
22 invaliduser@sub-domain.-2ld.tld
23 invaliduser@sub-domain.-2ld.tld.
24 invaliduser@subdomain-.2ld.tld
25 invaliduser@subdomain.2ld.t-ld.
26 invaliduser$@subdomain.2ld.t-ld.
27 v
28 validuser
29 valid_user
30 valid_user$
31 valid-user
32 valid-user$
33 validuser$
34 valid_user@subdomain.2ld.tld
35 valid_user$@subdomain.2ld.tld
36 valid-user@subdomain.2ld.tld
37 valid-user$@subdomain.2ld.tld
38 validuser@sub-domain.2-ld.tld
39 validuser@sub-domain.2ld.tld
40 validuser@subdomain.2-ld.tld
41 validuser@subdomain.2ld.tld
42 validuser@subdomain.2ld.t-ld
43 validuser$@sub-domain.2-ld.tld
44 validuser$@sub-domain.2ld.tld
45 validuser$@subdomain.2-ld.tld
Debian NAME_REGEX
Debian by default checks the username against a conservative regex. /etc/adduser.conf
man -L en --nh adduser.conf
1 …
2 NAME_REGEX
3 User and group names are checked against this regular
4 expression. If the name doesn't match this regexp,
5 user and group creation in adduser is refused unless
6 --force-badname is set. With --force-badname set, only
7 weak checks are performed. The default is the most
8 conservative ^[a-z][-a-z0-9]*$.
9 …
10 NOTES
11 VALID NAMES
12 adduser and addgroup enforce conformity to IEEE Std
13 1003.1-2001, which allows only the following
14 characters to appear in group and user names: letters,
15 digits, underscores, periods, at signs (@) and dashes.
16 The name may no start with a dash. The "$" sign is
17 allowed at the end of usernames (to conform to samba).
18
19 An additional check can be adjusted via the
20 configuration parameter NAME_REGEX to enforce a local
21 policy.
22 …
Hostnames
DNS constraints
Constraints from IETF RFC608 Host Names On-Line January 1974:
- up to 48 (2x24) characters drawn from the alphabet (A-Z), digits (0-9), and the minus sign (-) ... specifically, no blank or space characters allowed;
- The Host Name may be prefixed with an Official Network Name
of up to 24 characters enclosed in parentheses ()
- The Host Name may be prefixed with an Official Network Name
- no distinction between upper and lower case letters;
- the first character is a letter;
- the last character is NOT a minus sign;
- no other restrictions on content or syntax.
This means:
no underscores "_" and it doesn't matter if Microsoft DNS allows it.
Constraints from IETF RFC810 Host Table Specification
<official hostname> ::= <name> <name> ::= <letter>[*[<letter-or-digit-or-hyphen>]<letter-or-digit>]
- A host which serves as a GATEWAY should have "-GATEWAY" or "-GW" as part of its name.
- A host which is a TIP or a TAC should have "-TIP" or "-TAC" as part of its host name, if it is an ARPANET or DoD host.
The following definitions have been taken from the glossary of the DDN NEW USER GUIDE
TIP
- Terminal Interface Processor; predecessor of the TAC, serving a similar function. See TAC.
TAC
- Terminal Access Controller; special type of host attached to a PSN that allows direct terminal access to the DDN backbone.
TACACS
- TAC Access Control System; password system that limits use of TACs to authorized users.
Which is updated by IETF RFC952 DOD INTERNET HOST TABLE SPECIFICATION but the hostname grammer did not change
<official hostname> ::= <hname> <hname> ::= <name>*["."<name>] <name> ::= <let>[*[<let-or-digit-or-hyphen>]<let-or-digit>]
Single character names or nicknames are not allowed. Hmm, in the meantime they are used.
Here is a regex to check hostnames against RFC952
^[a-zA-Z][a-zA-Z0-9-]{,22}[a-zA-Z0-9]$
Updated by IETF RFC1123 Requirements for Internet Hosts -- Application and Support Section 2.1
- the restriction on the first character is relaxed to allow either a letter or a digit
- Host software MUST handle host names of up to 63 characters and SHOULD handle host names of up to 255 characters
Here are some regex to check hostnames against RFC1123
^[a-zA-Z0-9][a-zA-Z0-9-]{,61}[a-zA-Z0-9]$ ^[a-zA-Z0-9][a-zA-Z0-9-]{,253}[a-zA-Z0-9]$
man 1 hostname
man --locale=en 7 hostname
1 …
2 THE FQDN
3 The FQDN (Fully Qualified Domain Name) of the system is the
4 name that the resolver(3) returns for the host name, such as,
5 ursula.example.com. It is usually the hostname followed by
6 the DNS domain name (the part after the first dot). You can
7 check the FQDN using hostname --fqdn or the domain name using
8 dnsdomainname.
9
10 You cannot change the FQDN with hostname or dnsdomainname.
11
12 The recommended method of setting the FQDN is to make the
13 hostname be an alias for the fully qualified name using
14 /etc/hosts, DNS, or NIS. For example, if the hostname was
15 "ursula", one might have a line in /etc/hosts which reads
16
17 127.0.1.1 ursula.example.com ursula
18
19 Technically: The FQDN is the name getaddrinfo(3) returns for
20 the host name returned by gethostname(2). The DNS domain
21 name is the part after the first dot.
22
23 Therefore it depends on the configuration of the resolver
24 (usually in /etc/host.conf) how you can change it. Usually
25 the hosts file is parsed before DNS or NIS, so it is most
26 common to change the FQDN in /etc/hosts.
27
28 If a machine has multiple network interfaces/addresses or is
29 used in a mobile environment, then it may either have
30 multiple FQDNs/domain names or none at all. Therefore avoid
31 using hostname --fqdn, hostname --domain and dnsdomainname.
32 hostname --ip-address is subject to the same limitations so
33 it should be avoided as well.
34 …
35 OPTIONS
36 …
37 -A, --all-fqdns
38 Displays all FQDNs of the machine. This option
39 enumerates all configured network addresses on all
40 configured network interfaces, and translates them to
41 DNS domain names. Addresses that cannot be translated
42 (i.e. because they do not have an appropriate reverse
43 IP entry) are skipped. Note that different addresses
44 may resolve to the same name, therefore the output may
45 contain duplicate entries. Do not make any assumptions
46 about the order of the output.
47
48
49 …
50 -b, --boot
51 Always set a hostname; this allows the file specified
52 by -F to be non-existent or empty, in which case the
53 default hostname localhost will be used if none is yet
54 set.
55 …
56 -I, --all-ip-addresses
57 Display all network addresses of the host. This option
58 enumerates all configured addresses on all network
59 interfaces. The loopback interface and IPv6 link-local
60 addresses are omitted. Contrary to option -i, this
61 option does not depend on name resolution. Do not make
62 any assumptions about the order of the output.
63 …
64 FILES
65 /etc/hostname Historically this file was supposed to only
66 contain the hostname and not the full canonical FQDN.
67 Nowadays most software is able to cope with a full FQDN here.
68 This file is read at boot time by the system initialization
69 scripts to set the hostname.
70
71 /etc/hosts Usually, this is where one sets the domain name by
72 aliasing the host name to the FQDN.
73 …
Take aways
Use a single word in /etc/hostname
Default hostname is localhost, if /etc/hostname does not exist or is empty.
FQDN is to be resolved by DNS
You may set domain name/FQDN in /etc/hosts.
- Name resolution also depends on your resolver-config
/etc/host.conf, /etc/resolv.conf, /etc/nsswitch.conf
Use hostname -A, --all-fqdns and hostname -I, --all-ip-addresses to check something.
man 5 hostname
The same man-page is presented on CentOS Debian.
man --locale=en 5 hostname
1 NAME
2 hostname - Local hostname configuration file
3
4 SYNOPSIS
5 /etc/hostname
6
7 DESCRIPTION
8 The /etc/hostname file configures the name of the local
9 system that is set during boot using the sethostname(2)
10 system call. It should contain a single newline-terminated
11 hostname string. Comments (lines starting with a `#') are
12 ignored. The hostname may be a free-form string up to 64
13 characters in length; however, it is recommended that it
14 consists only of 7-bit ASCII lower-case characters and no
15 spaces or dots, and limits itself to the format allowed for
16 DNS domain name labels, even though this is not a strict
17 requirement.
18
19 You may use hostnamectl(1) to change the value of this file
20 during runtime from the command line. Use systemd-
21 firstboot(1) to initialize it on mounted (but not booted)
22 system images.
23
24 HISTORY
25 The simple configuration file format of /etc/hostname
26 originates from Debian GNU/Linux.
27 …
Take aways
- Okay, a "single newline-terminated hostname string" "and no spaces or dots",
- Differs in length from DNS
/etc/hostname "up to 64 characters"
- DNS "up to 63 characters"
man 7 hostname
man --locale=en 7 hostname
1 NAME
2 hostname - hostname resolution description
3
4 DESCRIPTION
5 Hostnames are domains, where a domain is a hierarchical, dot-
6 separated list of subdomains; for example, the machine
7 "monet", in the "example" subdomain of the "com" domain would
8 be represented as "monet.example.com".
9
10 Each element of the hostname must be from 1 to 63 characters
11 long and the entire hostname, including the dots, can be at
12 most 253 characters long. Valid characters for hostnames are
13 ASCII(7) letters from a to z, the digits from 0 to 9, and the
14 hyphen (-). A hostname may not start with a hyphen.
15
16 Hostnames are often used with network client and server
17 programs, which must generally translate the name to an
18 address for use. (This task is generally performed by either
19 getaddrinfo(3) or the obsolete gethostbyname(3).)
20
21 Hostnames are resolved by the NSS framework in glibc
22 according to the hosts configuration in nsswitch.conf. The
23 DNS-based name resolver (in the dns NSS service module)
24 resolves them in the following fashion.
25
26 If the name consists of a single component, that is, contains
27 no dot, and if the environment variable HOSTALIASES is set to
28 the name of a file, that file is searched for any string
29 matching the input hostname. The file should consist of
30 lines made up of two white-space separated strings, the first
31 of which is the hostname alias, and the second of which is
32 the complete hostname to be substituted for that alias. If a
33 case-insensitive match is found between the hostname to be
34 resolved and the first field of a line in the file, the
35 substituted name is looked up with no further processing.
36
37 If the input name ends with a trailing dot, the trailing dot
38 is removed, and the remaining name is looked up with no
39 further processing.
40
41 If the input name does not end with a trailing dot, it is
42 looked up by searching through a list of domains until a
43 match is found. The default search list includes first the
44 local domain, then its parent domains with at least 2 name
45 components (longest first). For example, in the domain
46 cs.example.com, the name lithium.cchem will be checked first
47 as lithium.cchem.cs.example and then as
48 lithium.cchem.example.com. lithium.cchem.com will not be
49 tried, as there is only one component remaining from the
50 local domain. The search path can be changed from the
51 default by a system-wide configuration file (see
52 resolver(5)).
53 …
Take aways
Somewhat stricter than man 5 hostname (especially in character set)
- Hostname is a domain
- Domains are hierarchical with up to 253 characters (incl. dots)
- Up to 63 characters per label
- Name resolution also depends on your resolver-config
/etc/host.conf, /etc/resolv.conf, /etc/nsswitch.conf
- Inputing a terminating dot during resolution prevents appending of search domains (up to ndots)
My idea of a hostname
A short hostname (without domain part/dots) is a name that must be unique to a host in a network. (A cluster is a kind of host, too.) A host may have more than one interface, with different physical addresses to be identified. IP-addresses of different networks are assigned to these interfaces, e.g. to allow routing or multi-homing. The hosts with the unique hostname is part of two distinct networks and its FQDNs are unique and its short hostname is unique in each network.
The hostname should furthermore consist of
- a human-readable 2-char customer id, which can be decoded by table
- a human-readable function of the host (like www, fw, …) which can be decoded by table
- a number that is unique in the (corporate) network, and should be a identification number in asset management.
This hostname/label should always receive an A-/AAAA- and PTR/PTR6-record in DNS.
Any other nice looking, pretty names can be e.g. a DNS CNAME-RR to this label or if necessary another A-/AAAA-Record to the same IP-address.
Tests on Linux-Hostnames
How does the system react? There are some variables to be taken into account
/etc/hostname
/etc/hosts
- DNS
Script to proof configuration
testify_hosts.sh
1 #!/bin/bash
2
3 SELF="${0##*/}"
4
5 HNAME="libertas"
6 DNAME="dungeon.rockstable.org"
7
8 FNAME="$HNAME.$DNAME"
9 IPV4="192.168.182.16"
10
11
12 unset FOUND
13 unset ACTIVE
14
15 description () {
16 cat <<-EOF
17
18 $SELF
19
20 This little script checks various combinations of
21 hostnames (with or without domains) as well as
22 entries in '/etc/hosts' and
23 outputs hostname as seen by OS progamms and runtime environments.
24 EOF
25 }
26
27 check_comment () {
28 local LINE="$1"
29 if grep -qE '^(\s*#)' <<< "$LINE"; then
30 echo "Line inactive."
31 #ACTIVE=0
32 else
33 echo "Line active."
34 #ACTIVE=1
35 fi
36 echo
37 }
38
39 get_hosts () {
40 local HOSTNAME="$1"
41 local INIT="$2"
42 local HLINES
43 HLINES="$(grep -Ee '^(\s*#)?.*\s+'"$HOSTNAME" /etc/hosts)"
44 if [ "$INIT" = "init" ]; then
45 grep '^#INIT#' <<< "$HLINES"
46 else
47 grep -v '^#INIT#' <<< "$HLINES"
48 fi
49 }
50
51 check_hline () {
52 local HLINE="$1"
53
54 [ -z "$HLINE" ] && return 0
55
56 if grep -qE "$HLINE" /etc/hosts; then
57 echo "Line found"
58 echo "$HLINE"
59 check_comment "$HLINE"
60 #FOUND=1
61 else
62 echo "Line not found"
63 #FOUND=0
64 fi
65 }
66
67 get_hostname () {
68 cat /etc/hostname
69 }
70
71 set_hostname () {
72 local HOSTNAME="$1"
73 echo -e '\n'"### Set hostname to '$HOSTNAME'"
74 echo "$HOSTNAME" > /etc/hostname
75 echo -en "/etc/hostname:"'\t'
76 get_hostname
77 hostname -F /etc/hostname
78 }
79
80 add_hosts_testify () {
81 local IP="$1"
82 local NAME="$2"
83 local ALIASES="$3"
84 local RHS
85
86 RHS="$NAME"
87 if [ -n "$ALIASES" ]; then
88 RHS+='\t'"$ALIASES"
89 fi
90 echo -e "$IP"'\t'"$RHS"'\t#TESTIFY' >> /etc/hosts
91 }
92
93 remove_hosts_testify () {
94 local IP="$1"
95 local NAME="$2"
96 local ALIASES="$3"
97 local RHS
98
99 RHS="$NAME"
100 if [ -n "$ALIASES" ]; then
101 RHS+='\t'"$ALIASES"
102 fi
103 sed -i "/$IP"'\t'"$RHS"'\t#TESTIFY/d' /etc/hosts
104 }
105
106 check_dns () {
107 cat <<-EOF
108
109 ### dig
110 dig "$HNAME" +short: '$(dig "$HNAME" +short)'
111 dig "$FNAME" +short: '$(dig "$FNAME" +short)'
112 dig -x "$IPV4" +short: '$(dig -x "$IPV4" +short)'
113 EOF
114 }
115
116 show_outputs () {
117 cat <<-EOF
118
119 ## Outputs
120 ### hostname
121 hostname: '$(hostname)'
122 hostname -s: '$(hostname -s)'
123 hostname -f: '$(hostname -f)'
124 hostname -A: '$(hostname -A)'
125 hostname -I: '$(hostname -I)'
126
127 ### hostnamectl
128 hostnamectl --static: '$(hostnamectl --static)'
129 hostnamectl --transient: '$(hostnamectl --transient)'
130 hostnamectl --pretty: '$(hostnamectl --pretty)'
131
132 ### postfix and runtimes
133 postconf -d myhostname:
134 '$(postconf -d myhostname)'
135 python <<< 'import socket;print(socket.gethostname())';:
136 '$(python <<< 'import socket;print(socket.gethostname())';)'
137 perl -MSys::Hostname -e'\$var = hostname;print \$var;':
138 '$(perl -MSys::Hostname -e'$var = hostname;print $var;')'
139 EOF
140 }
141
142 get_initial_state () {
143 HNAME_INIT="$(get_hostname)"
144 HLINES_INIT="$(get_hosts "$HNAME")"
145 cat <<-EOF
146
147 ################
148 ## Initial State
149 HNAME_INIT: '$HNAME_INIT'
150 HLINES_INIT:
151 $HLINES_INIT
152
153 hostnamectl:
154 $(hostnamectl)
155
156 EOF
157 }
158
159
160 activate_hline () {
161 local HLINE="$1"
162 local INIT="$2"
163
164 [ -z "$HLINE" ] && return 0
165
166 if [ "$INIT" = "init" ]; then
167 sed -i "s/^#INIT#$HLINE$/$HLINE/" /etc/hosts
168 else
169 sed -i "s/^#$HLINE$/$HLINE/" /etc/hosts
170 fi
171 }
172
173 deactivate_hline () {
174 local HLINE="$1"
175 local INIT="$2"
176
177 [ -z "$HLINE" ] && return 0
178
179 if [ "$INIT" = "init" ]; then
180 sed -i "s/^$HLINE$/#INIT#$HLINE/" /etc/hosts
181 else
182 sed -i "s/^$HLINE$/#$HLINE/" /etc/hosts
183 fi
184 }
185
186
187 ### MAIN
188
189 description
190 get_initial_state
191 echo "Deactivating initial lines in '/etc/hosts'"
192 while read -r HLINE; do
193 #check_hline "$HLINE"
194 deactivate_hline "$HLINE" init;
195 #check_hline "$HLINE"
196 done <<< "$HLINES_INIT"
197
198 check_dns
199
200 for NAME in "$FNAME" "$HNAME"; do
201 echo -e "\n\n################"
202 echo -e "## CURRENT NAME: '$NAME'"
203
204 #get_hosts "$HNAME"
205 #HLINES="$(get_hosts "$HNAME")"
206 #while read -r HLINE;do
207 # check_hline "$HLINE"
208 #done <<< "$HLINES"
209
210 set_hostname "$NAME"
211
212 show_outputs
213
214 echo -e '\n'"### Add custom hosts lines"
215 echo "### Only unqualified hostname"
216 add_hosts_testify "$IPV4" "$HNAME"
217 get_hosts "$HNAME"
218
219 show_outputs
220
221 echo -e '\n'"### Remove custom hosts lines"
222 remove_hosts_testify "$IPV4" "$HNAME"
223 get_hosts "$HNAME"
224
225 echo -e '\n'"### Add custom hosts lines"
226 echo "### Only full-qualified hostname"
227 add_hosts_testify "$IPV4" "$FNAME"
228 get_hosts "$HNAME"
229
230 show_outputs
231
232 echo -e '\n'"### Remove custom hosts lines"
233 remove_hosts_testify "$IPV4" "$FNAME"
234 get_hosts "$HNAME"
235
236 echo -e '\n'"### Add custom hosts lines"
237 echo "### Full-qualified hostname and alias"
238 add_hosts_testify "$IPV4" "$FNAME" "$HNAME"
239 get_hosts "$HNAME"
240
241 show_outputs
242
243 echo -e '\n'"### Remove custom hosts lines"
244 remove_hosts_testify "$IPV4" "$FNAME" "$HNAME"
245 get_hosts "$HNAME"
246
247 done
248
249 echo "Reactivating initial lines in '/etc/hosts'"
250 while read -r HLINE; do
251 #check_hline "$HLINE"
252 activate_hline "$HLINE" init
253 #check_hline "$HLINE"
254 done <<< "$HLINES_INIT"
255
256 echo -e '\n'"### Restoring initial hostname"
257 set_hostname "$HNAME_INIT
258
./testify_hosts.sh
1 testify_hosts.sh
2
3 This little script checks various combinations of
4 hostnames (with or without domains) as well as
5 entries in '/etc/hosts' and
6 outputs hostname as seen by OS progamms and runtime environments.
7
8 ################
9 ## Initial State
10 HNAME_INIT: 'libertas.dungeon.rockstable.org'
11 HLINES_INIT:
12 192.168.182.16 libertas.dungeon.rockstable.org libertas
13
14 hostnamectl:
15 Static hostname: libertas.dungeon.rockstable.org
16 Icon name: computer-desktop
17 Chassis: desktop
18 Machine ID: 8decd7208e6d4d0fbab614cfdf2d542f
19 Boot ID: 597ae1f9abd9478baf0423093bad8947
20 Operating System: Debian GNU/Linux bullseye/sid
21 Kernel: Linux 5.8.0-2-amd64
22 Architecture: x86-64
23
24 Deactivating initial lines in '/etc/hosts'
25
26 ### dig
27 dig "libertas" +short: '192.168.182.16'
28 dig "libertas.dungeon.rockstable.org" +short: '192.168.182.16'
29 dig -x "192.168.182.16" +short: 'libertas.dungeon.rockstable.org.'
30
31
32 ################
33 ## CURRENT NAME: 'libertas.dungeon.rockstable.org'
34
35 ### Set hostname to 'libertas.dungeon.rockstable.org'
36 /etc/hostname: libertas.dungeon.rockstable.org
37
38 ## Outputs
39 ### hostname
40 hostname: 'libertas.dungeon.rockstable.org'
41 hostname -s: 'libertas'
42 hostname -f: 'libertas.dungeon.rockstable.org'
43 hostname -A: 'libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org '
44 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
45
46 ### hostnamectl
47 hostnamectl --static: 'libertas.dungeon.rockstable.org'
48 hostnamectl --transient: 'libertas.dungeon.rockstable.org'
49 hostnamectl --pretty: ''
50
51 ### postfix and runtimes
52 postconf -d myhostname:
53 'myhostname = libertas.dungeon.rockstable.org'
54 python <<< 'import socket;print(socket.gethostname())';:
55 'libertas.dungeon.rockstable.org'
56 perl -MSys::Hostname -e'$var = hostname;print $var;':
57 'libertas.dungeon.rockstable.org'
58
59 ### Add custom hosts lines
60 ### Only unqualified hostname
61 192.168.182.16 libertas #TESTIFY
62
63 ## Outputs
64 ### hostname
65 hostname: 'libertas.dungeon.rockstable.org'
66 hostname -s: 'libertas'
67 hostname -f: 'libertas.dungeon.rockstable.org'
68 hostname -A: 'libertas libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org '
69 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
70
71 ### hostnamectl
72 hostnamectl --static: 'libertas.dungeon.rockstable.org'
73 hostnamectl --transient: 'libertas.dungeon.rockstable.org'
74 hostnamectl --pretty: ''
75
76 ### postfix and runtimes
77 postconf -d myhostname:
78 'myhostname = libertas.dungeon.rockstable.org'
79 python <<< 'import socket;print(socket.gethostname())';:
80 'libertas.dungeon.rockstable.org'
81 perl -MSys::Hostname -e'$var = hostname;print $var;':
82 'libertas.dungeon.rockstable.org'
83
84 ### Remove custom hosts lines
85
86 ### Add custom hosts lines
87 ### Only full-qualified hostname
88 192.168.182.16 libertas.dungeon.rockstable.org #TESTIFY
89
90 ## Outputs
91 ### hostname
92 hostname: 'libertas.dungeon.rockstable.org'
93 hostname -s: 'libertas'
94 hostname -f: 'libertas.dungeon.rockstable.org'
95 hostname -A: 'libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org '
96 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
97
98 ### hostnamectl
99 hostnamectl --static: 'libertas.dungeon.rockstable.org'
100 hostnamectl --transient: 'libertas.dungeon.rockstable.org'
101 hostnamectl --pretty: ''
102
103 ### postfix and runtimes
104 postconf -d myhostname:
105 'myhostname = libertas.dungeon.rockstable.org'
106 python <<< 'import socket;print(socket.gethostname())';:
107 'libertas.dungeon.rockstable.org'
108 perl -MSys::Hostname -e'$var = hostname;print $var;':
109 'libertas.dungeon.rockstable.org'
110
111 ### Remove custom hosts lines
112
113 ### Add custom hosts lines
114 ### Full-qualified hostname and alias
115 192.168.182.16 libertas.dungeon.rockstable.org libertas #TESTIFY
116
117 ## Outputs
118 ### hostname
119 hostname: 'libertas.dungeon.rockstable.org'
120 hostname -s: 'libertas'
121 hostname -f: 'libertas.dungeon.rockstable.org'
122 hostname -A: 'libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org libertas.dungeon.rockstable.org '
123 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
124
125 ### hostnamectl
126 hostnamectl --static: 'libertas.dungeon.rockstable.org'
127 hostnamectl --transient: 'libertas.dungeon.rockstable.org'
128 hostnamectl --pretty: ''
129
130 ### postfix and runtimes
131 postconf -d myhostname:
132 'myhostname = libertas.dungeon.rockstable.org'
133 python <<< 'import socket;print(socket.gethostname())';:
134 'libertas.dungeon.rockstable.org'
135 perl -MSys::Hostname -e'$var = hostname;print $var;':
136 'libertas.dungeon.rockstable.org'
137
138 ### Remove custom hosts lines
139
140
141 ################
142 ## CURRENT NAME: 'libertas'
143
144 ### Set hostname to 'libertas'
145 /etc/hostname: libertas
146
147 ## Outputs
148 ### hostname
149 hostname: 'libertas'
150 hostname -s: 'libertas'
151 hostname -f: 'libertas.dungeon.rockstable.org'
152 hostname -A: 'libertas.dungeon.rockstable.org libertas libertas libertas '
153 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
154
155 ### hostnamectl
156 hostnamectl --static: 'libertas'
157 hostnamectl --transient: 'libertas'
158 hostnamectl --pretty: ''
159
160 ### postfix and runtimes
161 postconf -d myhostname:
162 'myhostname = libertas.localdomain'
163 python <<< 'import socket;print(socket.gethostname())';:
164 'libertas'
165 perl -MSys::Hostname -e'$var = hostname;print $var;':
166 'libertas'
167
168 ### Add custom hosts lines
169 ### Only unqualified hostname
170 192.168.182.16 libertas #TESTIFY
171
172 ## Outputs
173 ### hostname
174 hostname: 'libertas'
175 hostname -s: 'libertas'
176 hostname -f: 'libertas'
177 hostname -A: 'libertas libertas libertas libertas '
178 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
179
180 ### hostnamectl
181 hostnamectl --static: 'libertas'
182 hostnamectl --transient: 'libertas'
183 hostnamectl --pretty: ''
184
185 ### postfix and runtimes
186 postconf -d myhostname:
187 'myhostname = libertas.localdomain'
188 python <<< 'import socket;print(socket.gethostname())';:
189 'libertas'
190 perl -MSys::Hostname -e'$var = hostname;print $var;':
191 'libertas'
192
193 ### Remove custom hosts lines
194
195 ### Add custom hosts lines
196 ### Only full-qualified hostname
197 192.168.182.16 libertas.dungeon.rockstable.org #TESTIFY
198
199 ## Outputs
200 ### hostname
201 hostname: 'libertas'
202 hostname -s: 'libertas'
203 hostname -f: 'libertas.dungeon.rockstable.org'
204 hostname -A: 'libertas.dungeon.rockstable.org libertas libertas libertas '
205 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
206
207 ### hostnamectl
208 hostnamectl --static: 'libertas'
209 hostnamectl --transient: 'libertas'
210 hostnamectl --pretty: ''
211
212 ### postfix and runtimes
213 postconf -d myhostname:
214 'myhostname = libertas.localdomain'
215 python <<< 'import socket;print(socket.gethostname())';:
216 'libertas'
217 perl -MSys::Hostname -e'$var = hostname;print $var;':
218 'libertas'
219
220 ### Remove custom hosts lines
221
222 ### Add custom hosts lines
223 ### Full-qualified hostname and alias
224 192.168.182.16 libertas.dungeon.rockstable.org libertas #TESTIFY
225
226 ## Outputs
227 ### hostname
228 hostname: 'libertas'
229 hostname -s: 'libertas'
230 hostname -f: 'libertas.dungeon.rockstable.org'
231 hostname -A: 'libertas.dungeon.rockstable.org libertas libertas libertas '
232 hostname -I: '192.168.182.16 192.168.100.1 172.17.0.1 fd93:56fb:daf7:0:c87a:4674:d313:c6ca '
233
234 ### hostnamectl
235 hostnamectl --static: 'libertas'
236 hostnamectl --transient: 'libertas'
237 hostnamectl --pretty: ''
238
239 ### postfix and runtimes
240 postconf -d myhostname:
241 'myhostname = libertas.localdomain'
242 python <<< 'import socket;print(socket.gethostname())';:
243 'libertas'
244 perl -MSys::Hostname -e'$var = hostname;print $var;':
245 'libertas'
246
247 ### Remove custom hosts lines
248 Reactivating initial lines in '/etc/hosts'
249
250 ### Restoring initial hostname
251
252 ### Set hostname to 'libertas.dungeon.rockstable.org'
253 /etc/hostname: libertas.dungeon.rockstable.org
Take aways:
A single string without dots should reside in /etc/hostname.
A entry in /etc/hosts has preference to reverse DNS resolution. Even if it's unmaintained, stall and wrong.
- Linux determines its fqdn using reverse DNS,
when there is no matching entry in /etc/hosts.
- If there is no internal DNS-resolution (e.g. only Google-Public-DNS, …),
/etc/hosts is the only meaningful way to provide a fqdn/domain-name.
Postfix needs a domain specified explicitly in $mydomain. It does correctly figure out the hostname, but misses the domain-name and therefore appends .localdomain. Something seems to be broken there.
Domain names
Take a look at IETF RFC1034 DOMAIN NAMES - CONCEPTS AND FACILITIES
3. DOMAIN NAME SPACE and RESOURCE RECORDS 3.1. Name space specifications and terminology The domain name space is a tree structure. Each node and leaf on the tree corresponds to a resource set (which may be empty). The domain system makes no distinctions between the uses of the interior nodes and leaves, and this memo uses the term "node" to refer to both. Each node has a label, which is zero to 63 octets in length. Brother nodes may not have the same label, although the same label can be used for nodes which are not brothers. One label is reserved, and that is the null (i.e., zero length) label used for the root. The domain name of a node is the list of the labels on the path from the node to the root of the tree. By convention, the labels that compose a domain name are printed or read left to right, from the most specific (lowest, farthest from the root) to the least specific (highest, closest to the root). Internally, programs that manipulate domain names should represent them as sequences of labels, where each label is a length octet followed by an octet string. Because all domain names end at the root, which has a null string for a label, these internal representations can use a length byte of zero to terminate a domain name. By convention, domain names can be stored with arbitrary case, but domain name comparisons for all present domain functions are done in a case-insensitive manner, assuming an ASCII character set, and a high order zero bit. This means that you are free to create a node with label "A" or a node with label "a", but not both as brothers; you could refer to either using "a" or "A". When you receive a domain name or label, you should preserve its case. The rationale for this choice is that we may someday need to add full binary domain names for new services; existing services would not be changed. When a user needs to type a domain name, the length of each label is omitted and the labels are separated by dots ("."). Since a complete domain name ends with the root label, this leads to a printed form which ends in a dot. We use this property to distinguish between: - a character string which represents a complete domain name (often called "absolute"). For example, "poneria.ISI.EDU." - a character string that represents the starting labels of a domain name which is incomplete, and should be completed by local software using knowledge of the local domain (often called "relative"). For example, "poneria" used in the ISI.EDU domain. Relative names are either taken relative to a well known origin, or to a list of domains used as a search list. Relative names appear mostly at the user interface, where their interpretation varies from implementation to implementation, and in master files, where they are relative to a single origin domain name. The most common interpretation uses the root "." as either the single origin or as one of the members of the search list, so a multi-label relative name is often one where the trailing dot has been omitted to save typing. To simplify implementations, the total number of octets that represent a domain name (i.e., the sum of all label octets and label lengths) is limited to 255. A domain is identified by a domain name, and consists of that part of the domain name space that is at or below the domain name which specifies the domain. A domain is a subdomain of another domain if it is contained within that domain. This relationship can be tested by seeing if the subdomain's name ends with the containing domain's name. For example, A.B.C.D is a subdomain of B.C.D, C.D, D, and " ".
Summery:
- The domain name space is a tree structure. Each node and leaf on the tree corresponds to a resource set (which may be empty).
- Each node has a label, which is zero to 63 octets in length.
The labels are separated by dots (".").
- A domain name (i.e., the sum of all label octets and label lengths) is limited to 255.
- One label is reserved, and that is the null (i.e., zero length) label used for the root.