Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

hostname

Show the host name (and its FQDN, domain or IP addresses), or set it until the next reboot.

Niveau
RHCSA-examen
Groep
Netwerk
Root nodig
Voor wijzigingen
Pakket
hostname
Ook
dnsdomainname, domainname

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

hostname prints the current host name. Options show the FQDN, the DNS domain or all IP addresses.

Setting a name with hostname NAME lasts only until reboot. To set it for good on RHEL, use hostnamectl set-hostname NAME (writes /etc/hostname).

Zo schrijf je het

hostname [OPTION]
hostname [-b] [-F FILE] [NAME]

Opties 12

Meest gebruikt

-s, --short
Short name (until the first dot).
-f, --fqdn, --long
Fully qualified domain name (from DNS or /etc/hosts).
-d, --domain
The DNS domain part.
-i, --ip-address
Addresses of the host name (by name lookup).
-I, --all-ip-addresses
All addresses of all interfaces (no lookup).
-a, --alias
Alias names (old, not recommended).
-A, --all-fqdns
All FQDNs of the host addresses.
-y, --yp, --nis
The NIS domain name.
-b, --boot
When setting: use a default name if none is given.
-F, --file FILE
Read the name from a file.
-h, --help
Show help.
-V, --version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Show the host name

    hostname
    server1.example.com

    RHEL often uses the full name as host name.

  2. 2Short name and FQDN

    hostname -s; hostname -f
    server1
    server1.example.com

    -f needs /etc/hosts or DNS to know the full name.

  3. 3All IP addresses

    hostname -I
    192.168.122.10 fe80::5054:ff:fe12:3456

    Quick way to find the IP of a fresh VM.

  4. 4Domain part

    hostname -d
    example.com

    Same as dnsdomainname.

  5. 5Set a name until reboot

    hostname test1

    For a quick test only.

  6. 6Set the name for good

    hostnamectl set-hostname server1.example.com

    Writes /etc/hostname (the RHCSA way).

  7. 7Use the name in a prompt or file name

    tar -czf /backup/$(hostname -s)-etc-$(date +%F).tgz /etc

    Each server makes a different file name.

  8. 8Check the name for certificates

    hostname -f; getent hosts $(hostname -f)

    The FQDN must resolve to the server IP before you request a TLS certificate.

  9. 9Find wrong FQDN settings

    hostname -f
    hostname: Name or service not known

    Add the name to /etc/hosts or DNS.

  10. 10Show the domain of NIS

    hostname -y

    Only for old NIS setups.

Bestanden

/etc/hostname
The static host name.
/etc/hosts
Local name to address list.

Exitcodes

0 :: Done. 1 :: Error.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man hostname