How to Use the hostname Command in Linux

 

1. Check the local system version

[root@server-01 ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

2. Help description of hostname in Linux


[root@server-01 ~]# hostname --help
Usage: hostname [-b] {hostname|-F file}         set host name (from file)
       hostname [-a|-A|-d|-f|-i|-I|-s|-y]       display formatted name
       hostname                                 display host name

       {yp,nis,}domainname {nisdomain|-F file}  set NIS domain name (from file)
       {yp,nis,}domainname                      display NIS domain name

       dnsdomainname                            display dns domain name

       hostname -V|--version|-h|--help          print info and exit

Program name:
       {yp,nis,}domainname=hostname -y
       dnsdomainname=hostname -d

Program options:
    -a, --alias            alias names
    -A, --all-fqdns        all long host names (FQDNs)
    -b, --boot             set default hostname if none available
    -d, --domain           DNS domain name
    -f, --fqdn, --long     long host name (FQDN)
    -F, --file             read host name or NIS domain name from given file
    -i, --ip-address       addresses for the host name
    -I, --all-ip-addresses all addresses for the host
    -s, --short            short host name
    -y, --yp, --nis        NIS/YP domain name

Description:
   This command can get or set the host name or the NIS domain name. You can
   also get the DNS domain or the FQDN (fully qualified domain name).
   Unless you are using bind or NIS for host lookups you can change the
   FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
   part of the FQDN) in the /etc/hosts file.

3. Chinese help description of hostname

Usage: hostname[-b]{hostname |-F file} set hostname (from file)

hostname [-a|-a|-d|-f|-i|-i|-s|-y] display formatted name

hostname show hostname
{yp,nis,} domain name {nisdomain | -F file} set nis domain name (from file)

{yp, nis, } domain names show nis domain names
dnsdomainname show dns domain name
hostname -V|--version|-h|--help print info and exit
Program name:

{yp,nis,}domain=hostname-y

dnsdomainname=hostname -d
Program options:

-a, --alias alias

-A, --all fqdns all long hostnames (FQDNs)

-b, --if no hostname is available, start setting default hostname

-d, --domain DNS domain name

-f, --fqdn, --long hostname (fqdn)

-F, --Read hostnames or NIS domain names from the given file

-i, --the ip address of the hostname

-I, --all ip address all addresses of the host

-s, --short hostname

-y, --yp, --nis nis/yp domain name
describe:

This command can get or set the hostname or NIS domain name. you can

It is also possible to get the DNS domain or FQDN (Fully Qualified Domain Name).

Unless you're using bind or NIS for host lookups, you can change

FQDN (Fully Qualified Domain Name) and DNS Domain Name (

part of the FQDN).
Fourth, the basic use of the hostname command

1. Check the computer name

[root@server-01 ~]# hostname
server-01

2. View all IP addresses on the machine

[root@server-01 ~]# hostname -I
192.168.200.150 172.17.0.1 172.21.0.1 172.19.0.1 172.20.0.1 

3. View the host FQDN

[root@server-01 ~]# hostname -f
server-01

4. View the short host name

[root@server-01 ~]# hostname -s
server-01

Five, the use of hostnamectl

1. View host details

[root@server-01 ~]# hostnamectl
   Static hostname: server-01
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 8daa9318d5564417b557c0bf5b06c3b8
           Boot ID: f45c90c8ca254ef28bf4da5b04bdafdf
    Virtualization: kvm
  Operating System: CentOS Linux 8 (Core)
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-240.10.1.el8_3.x86_64
      Architecture: x86-64

2. Set the hostname

[root@server-01 ~]# hostnamectl set-hostname test

3. The command help of hostnamectl

[root@server-01 ~]# hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...

Query or change system hostname.

  -h --help              Show this help
     --version           Show package version
     --no-ask-password   Do not prompt for password
  -H --host=[USER@]HOST  Operate on remote host
  -M --machine=CONTAINER Operate on local container
     --transient         Only set transient hostname
     --static            Only set static hostname
     --pretty            Only set pretty hostname

Commands:
  status                 Show current hostname settings
  set-hostname NAME      Set system hostname
  set-icon-name NAME     Set icon name for host
  set-chassis NAME       Set chassis type for host
  set-deployment NAME    Set deployment environment for host
  set-location NAME      Set location for host
Post a Comment (0)
Previous Post Next Post