| 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 |
.SS "SET NAME" |
| 84 |
When called with one argument or with the |
| 85 |
.B \-\-file |
| 86 |
option, the commands set the host name or the NIS/YP domain name. |
| 87 |
.B hostname |
| 88 |
uses the |
| 89 |
.BR sethostname (2) |
| 90 |
function, while all of the three |
| 91 |
.BR domainname , |
| 92 |
.B ypdomainname |
| 93 |
and |
| 94 |
.B nisdomainname |
| 95 |
use |
| 96 |
.BR setdomainname (2). |
| 97 |
Note, that this is effective only until the next reboot. |
| 98 |
Edit /etc/hostname for permanent change. |
| 99 |
.LP |
| 100 |
Note, that only the super-user can change the names. |
| 101 |
.LP |
| 102 |
It is not possible to set the FQDN or the DNS domain name with the |
| 103 |
.B dnsdomainname |
| 104 |
command (see |
| 105 |
.B THE FQDN |
| 106 |
below). |
| 107 |
.LP |
| 108 |
The host name is usually set once at system startup in |
| 109 |
.I /etc/init.d/hostname.sh |
| 110 |
(normally by reading the contents of a file which contains |
| 111 |
the host name, e.g. |
| 112 |
.IR /etc/hostname ). |
| 113 |
|
| 114 |
.SS THE FQDN |
| 115 |
The FQDN (Fully Qualified Domain Name) of the system is the name that the |
| 116 |
.BR resolver (3) |
| 117 |
returns for the host name, such as, |
| 118 |
.IR ursula.example.com . |
| 119 |
It is usually the hostname followed by the DNS domain name (the part |
| 120 |
after the first dot). You can check the FQDN using |
| 121 |
.B hostname \-\-fqdn |
| 122 |
or the domain name using |
| 123 |
.BR "dnsdomainname" . |
| 124 |
.LP |
| 125 |
You cannot change the FQDN with |
| 126 |
.B hostname |
| 127 |
or |
| 128 |
.BR dnsdomainname . |
| 129 |
.LP |
| 130 |
The recommended method of setting the FQDN is to make the hostname be |
| 131 |
an alias for the fully qualified name using |
| 132 |
.IR /etc/hosts , |
| 133 |
DNS, or NIS. For example, if the hostname was "ursula", one might have a line in |
| 134 |
.I /etc/hosts |
| 135 |
which reads |
| 136 |
.LP |
| 137 |
.RS |
| 138 |
127.0.1.1 ursula.example.com ursula |
| 139 |
.RE |
| 140 |
.LP |
| 141 |
Technically: The FQDN is the name |
| 142 |
.BR getaddrinfo (3) |
| 143 |
returns for the host name returned by |
| 144 |
.BR gethostname (2). |
| 145 |
The DNS domain name is the part after the first dot. |
| 146 |
.LP |
| 147 |
Therefore it depends on the configuration of the resolver (usually in |
| 148 |
.IR /etc/host.conf ) |
| 149 |
how you can change it. Usually the hosts file is parsed before DNS or |
| 150 |
NIS, so it is most common to change the FQDN in |
| 151 |
.IR /etc/hosts . |
| 152 |
.LP |
| 153 |
If a machine has multiple network interfaces/addresses or is used in a |
| 154 |
mobile environment, then it may either have multiple FQDNs/domain names |
| 155 |
or none at all. Therefore avoid using |
| 156 |
.BR "hostname \-\-fqdn" , |
| 157 |
.B hostname \-\-domain |
| 158 |
and |
| 159 |
.BR "dnsdomainname" . |
| 160 |
.B hostname \-\-ip-address |
| 161 |
is subject to the same limitations so it should be avoided as well. |
| 162 |
|
| 163 |
.SH OPTIONS |
| 164 |
.TP |
| 165 |
.I "\-a, \-\-alias" |
| 166 |
Display the alias name of the host (if used). This option is deprecated |
| 167 |
and should not be used anymore. |
| 168 |
.TP |
| 169 |
.I "\-A, \-\-all-fqdns" |
| 170 |
Displays all FQDNs of the machine. This option enumerates all configured |
| 171 |
network addresses on all configured network interfaces, and translates |
| 172 |
them to DNS domain names. Addresses that cannot be translated (i.e. because |
| 173 |
they do not have an appropriate reverse IP entry) are skipped. Note that |
| 174 |
different addresses may resolve to the same name, therefore the output may |
| 175 |
contain duplicate entries. Do not make any assumptions about the order of the |
| 176 |
output. |
| 177 |
.TP |
| 178 |
.I "\-b, \-\-boot" |
| 179 |
Always set a hostname; this allows the file specified by \fI\-F\fR to be |
| 180 |
non-existent or empty, in which case the default hostname \fIlocalhost\fR |
| 181 |
will be used if none is yet set. |
| 182 |
.TP |
| 183 |
.I "\-d, \-\-domain" |
| 184 |
Display the name of the DNS domain. Don't use the command |
| 185 |
.B domainname |
| 186 |
to get the DNS domain name because it will show the NIS domain name and |
| 187 |
not the DNS domain name. Use |
| 188 |
.B dnsdomainname |
| 189 |
instead. See the warnings in section |
| 190 |
.B THE FQDN |
| 191 |
above, and avoid using this option. |
| 192 |
.TP |
| 193 |
.I "\-f, \-\-fqdn, \-\-long" |
| 194 |
Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a |
| 195 |
short host name and the DNS domain name. Unless you are using bind or NIS |
| 196 |
for host lookups you can change the FQDN and the DNS domain name (which is |
| 197 |
part of the FQDN) in the \fI/etc/hosts\fR file. See the warnings in section |
| 198 |
.B THE FQDN |
| 199 |
above and use |
| 200 |
.B hostname \-\-all-fqdns |
| 201 |
instead wherever possible. |
| 202 |
.TP |
| 203 |
.I "\-F, \-\-file filename" |
| 204 |
Read the host name from the specified file. Comments (lines starting with |
| 205 |
a `#') are ignored. |
| 206 |
.TP |
| 207 |
.I "\-i, \-\-ip-address" |
| 208 |
Display the network address(es) of the host name. Note that this works only |
| 209 |
if the host name can be resolved. Avoid using this option; use |
| 210 |
.B hostname \-\-all-ip-addresses |
| 211 |
instead. |
| 212 |
.TP |
| 213 |
.I "\-I, \-\-all-ip-addresses" |
| 214 |
Display all network addresses of the host. This option enumerates all |
| 215 |
configured addresses on all network interfaces. The loopback interface and IPv6 |
| 216 |
link-local addresses are omitted. Contrary to option \fI\-i\fR, this option |
| 217 |
does not depend on name resolution. Do not make any assumptions about the |
| 218 |
order of the output. |
| 219 |
.TP |
| 220 |
.I "\-s, \-\-short" |
| 221 |
Display the short host name. This is the host name cut at the first dot. |
| 222 |
.TP |
| 223 |
.I "\-V, \-\-version" |
| 224 |
Print version information on standard output and exit successfully. |
| 225 |
.TP |
| 226 |
.I "\-y, \-\-yp, \-\-nis" |
| 227 |
Display the NIS domain name. If a parameter is given (or |
| 228 |
.B \-\-file name |
| 229 |
) then root can also set a new NIS domain. |
| 230 |
.TP |
| 231 |
.I "\-h, \-\-help" |
| 232 |
Print a usage message and exit. |
| 233 |
.SH NOTES |
| 234 |
The address families |
| 235 |
.B hostname |
| 236 |
tries when looking up the FQDN, aliases and network addresses of the |
| 237 |
host are determined by the configuration of your resolver. |
| 238 |
For instance, on GNU Libc systems, the resolver can be instructed to |
| 239 |
try IPv6 lookups first by using the |
| 240 |
.B inet6 |
| 241 |
option in |
| 242 |
.BR /etc/resolv.conf . |
| 243 |
.SH FILES |
| 244 |
.B /etc/hostname |
| 245 |
Historically this file was supposed to only contain the hostname and not the |
| 246 |
full canonical FQDN. Nowadays most software is able to cope with a full FQDN |
| 247 |
here. This file is read at boot time by the system initialization scripts to |
| 248 |
set the hostname. |
| 249 |
.LP |
| 250 |
.B /etc/hosts |
| 251 |
Usually, this is where one sets the domain name by aliasing the host name to |
| 252 |
the FQDN. |
| 253 |
.SH AUTHORS |
| 254 |
Peter Tobias, <[email protected]> |
| 255 |
.br |
| 256 |
Bernd Eckenfels, <[email protected]> (NIS and manpage). |
| 257 |
.br |
| 258 |
Michael Meskes, <[email protected]> |
| 259 |
.br |