1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
.TH HOSTNAME 1 "2009-09-16" "net-tools" "Linux Programmer's Manual"
.SH NAME
hostname \- show or set the system's host name
.br
domainname \- show or set the system's NIS/YP domain name
.br
ypdomainname \- show or set the system's NIS/YP domain name
.br
nisdomainname \- show or set the system's NIS/YP domain name
.br
dnsdomainname \- show the system's DNS domain name
.br
.SH SYNOPSIS
.B hostname
.RB [ \-a|\-\-alias ]
.RB [ \-d|\-\-domain ]
.RB [ \-f|\-\-fqdn|\-\-long ]
.RB [ \-A|\-\-all-fqdns ]
.RB [ \-i|\-\-ip-address ]
.RB [ \-I|\-\-all-ip-addresses ]
.RB [ \-s|\-\-short ]
.RB [ \-y|\-\-yp|\-\-nis ]
.br
.B hostname
.RB [ \-b|\-\-boot ]
.RB [ \-F|\-\-file\ filename ]
.RB [ hostname ]
.br
.B hostname
.RB [ \-h|\-\-help ]
.RB [ \-V|\-\-version ]
.PP
.B domainname
.RB [ nisdomain ]
.RB [ \-F\ file ]
.br
.B ypdomainname
.RB [ nisdomain ]
.RB [ \-F\ file ]
.br
.B nisdomainname
.RB [ nisdomain ]
.RB [ \-F\ file ]
.PP
.B dnsdomainname
.SH DESCRIPTION
.B Hostname
is used to display the system's DNS name, and to display or set its hostname or
NIS domain name.
.SS "GET NAME"
When called without any arguments, the program displays the current
names:
.LP
.B hostname
will print the name of the system as returned by the
.BR gethostname (2)
function.
.LP
.B domainname
will print the NIS domainname of the system.
.B domainname
uses the
.BR gethostname (2)
function, while
.B ypdomainname
and
.B nisdomainname
use the
.BR getdomainname (2).
.LP
.B dnsdomainname
will print the domain part of the FQDN (Fully Qualified Domain Name). The
complete FQDN of the system is returned with
.B hostname \-\-fqdn
(but see the warnings in section
.B THE FQDN
below).
.LP
The function
.BR gethostname(2)
is used to get the hostname. When the
.BR "hostname \-a, \-d, \-f or \-i"
is called will
.BR gethostbyname(3)
be called. The difference in
.BR gethostname(2)
and
.BR gethostbyname(3)
is that
.BR gethostbyname(5)
is network aware, so it consults
.IR /etc/nsswitch.conf
and
.IR /etc/host.conf
to decide whether to read information in
.IR /etc/hostname
or
.IR /etc/hosts
.SS "SET NAME"
When called with one argument or with the
.B \-\-file
option, the commands set the host name or the NIS/YP domain name.
.B hostname
uses the
.BR sethostname (2)
function, while all of the three
.BR domainname ,
.B ypdomainname
and
.B nisdomainname
use
.BR setdomainname (2).
Note, that this is effective only until the next reboot.
Edit /etc/hostname for permanent change.
.LP
Note, that only the super-user can change the names.
.LP
It is not possible to set the FQDN or the DNS domain name with the
.B dnsdomainname
command (see
.B THE FQDN
below).
.LP
The host name is usually set once at system startup
(normally by reading the contents of a file which contains
the host name, e.g.
.IR /etc/hostname ).
.SS THE FQDN
The FQDN (Fully Qualified Domain Name) of the system is the name that the
.BR resolver (3)
returns for the host name, such as,
.IR ursula.example.com .
It is usually the hostname followed by the DNS domain name (the part
after the first dot). You can check the FQDN using
.B hostname \-\-fqdn
or the domain name using
.BR "dnsdomainname" .
.LP
You cannot change the FQDN with
.B hostname
or
.BR dnsdomainname .
.LP
The recommended method of setting the FQDN is to make the hostname be
an alias for the fully qualified name using
.IR /etc/hosts ,
DNS, or NIS. For example, if the hostname was "ursula", one might have a line in
.I /etc/hosts
which reads
.LP
.RS
127.0.1.1 ursula.example.com ursula
.RE
.LP
Technically: The FQDN is the name
.BR getaddrinfo (3)
returns for the host name returned by
.BR gethostname (2).
The DNS domain name is the part after the first dot.
.LP
Therefore it depends on the configuration of the resolver (usually in
.IR /etc/host.conf )
how you can change it. Usually the hosts file is parsed before DNS or
NIS, so it is most common to change the FQDN in
.IR /etc/hosts .
.LP
If a machine has multiple network interfaces/addresses or is used in a
mobile environment, then it may either have multiple FQDNs/domain names
or none at all. Therefore avoid using
.BR "hostname \-\-fqdn" ,
.B hostname \-\-domain
and
.BR "dnsdomainname" .
.B hostname \-\-ip-address
is subject to the same limitations so it should be avoided as well.
.SH OPTIONS
.TP
.I "\-a, \-\-alias"
Display the alias name of the host (if used). This option is deprecated
and should not be used anymore.
.TP
.I "\-A, \-\-all-fqdns"
Displays all FQDNs of the machine. This option enumerates all configured
network addresses on all configured network interfaces, and translates
them to DNS domain names. Addresses that cannot be translated (i.e. because
they do not have an appropriate reverse IP entry) are skipped. Note that
different addresses may resolve to the same name, therefore the output may
contain duplicate entries. Do not make any assumptions about the order of the
output.
.TP
.I "\-b, \-\-boot"
Always set a hostname; this allows the file specified by \fI\-F\fR to be
non-existent or empty, in which case the default hostname \fIlocalhost\fR
will be used if none is yet set.
.TP
.I "\-d, \-\-domain"
Display the name of the DNS domain. Don't use the command
.B domainname
to get the DNS domain name because it will show the NIS domain name and
not the DNS domain name. Use
.B dnsdomainname
instead. See the warnings in section
.B THE FQDN
above, and avoid using this option.
.TP
.I "\-f, \-\-fqdn, \-\-long"
Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a
short host name and the DNS domain name. Unless you are using bind or NIS
for host lookups you can change the FQDN and the DNS domain name (which is
part of the FQDN) in the \fI/etc/hosts\fR file. See the warnings in section
.B THE FQDN
above und use
.B hostname \-\-all-fqdns
instead wherever possible.
.TP
.I "\-F, \-\-file filename"
Read the host name from the specified file. Comments (lines starting with
a `#') are ignored.
.TP
.I "\-i, \-\-ip-address"
Display the network address(es) of the host name. Note that this works only
if the host name can be resolved. Avoid using this option; use
.B hostname \-\-all-ip-addresses
instead.
.TP
.I "\-I, \-\-all-ip-addresses"
Display all network addresses of the host. This option enumerates all
configured addresses on all network interfaces. The loopback interface and IPv6
link-local addresses are omitted. Contrary to option \fI\-i\fR, this option
does not depend on name resolution. Do not make any assumptions about the
order of the output.
.TP
.I "\-s, \-\-short"
Display the short host name. This is the host name cut at the first dot.
.TP
.I "\-V, \-\-version"
Print version information on standard output and exit successfully.
.TP
.I "\-y, \-\-yp, \-\-nis"
Display the NIS domain name. If a parameter is given (or
.B \-\-file name
) then root can also set a new NIS domain.
.TP
.I "\-h, \-\-help"
Print a usage message and exit.
.SH NOTES
The address families
.B hostname
tries when looking up the FQDN, aliases and network addresses of the
host are determined by the configuration of your resolver.
For instance, on GNU Libc systems, the resolver can be instructed to
try IPv6 lookups first by using the
.B inet6
option in
.BR /etc/resolv.conf .
.SH FILES
.B /etc/hostname
Historically this file was supposed to only contain the hostname and not the
full canonical FQDN. Nowadays most software is able to cope with a full FQDN
here. This file is read at boot time by the system initialization scripts to
set the hostname.
.LP
.B /etc/hosts
Usually, this is where one sets the domain name by aliasing the host name to
the FQDN.
.SH AUTHORS
Peter Tobias, <tobias@et-inf.fho-emden.de>
.br
Bernd Eckenfels, <net-tools@lina.inka.de> (NIS and manpage).
.br
Michael Meskes, <meskes@debian.org>
.br
|