Debian Codegraph @

upstream/fedora-44/man1/hostname.1

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