Linux系统之hostname相关命令基本使用

简介: Linux系统之hostname相关命令基本使用

一、检查本地系统版本

[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"


二、hostname在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.

三、hostname的中文帮助说明


用法:hostname[-b]{hostname |-F file}设置主机名(来自文件)

主机名[-a|-a|-d|-f|-i|-i|-s|-y]显示格式化名称

主机名显示主机名



{yp,nis,}域名{nisdomain |-F文件}设置nis域名(来自文件)

{yp,nis,}域名显示nis域名



dnsdomainname显示dns域名



主机名-V|--版本|-h|--帮助打印信息并退出



程序名称:

{yp,nis,}域名=主机名-y

dnsdomainname=主机名-d



程序选项:

-a、 --别名别名

-A、 --所有fqdns所有长主机名(FQDN)

-b、 --如果没有可用的主机名,则启动设置默认主机名

-d、 --域DNS域名

-f、 --fqdn,--长主机名(fqdn)

-F、 --从给定文件读取主机名或NIS域名

-i、 --主机名的ip地址地址

-I、 --所有ip地址主机的所有地址

-s、 --短主机名

-y、 --yp,--nis nis/yp域名



描述:

此命令可以获取或设置主机名或NIS域名。你可以

还可以获取DNS域或FQDN(完全限定域名)。

除非您使用绑定或NIS进行主机查找,否则可以更改

FQDN(完全限定域名)和DNS域名(

FQDN的一部分)。

四、hostname命令的基本使用

1.查看计算机名

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

2.查看本机上所有IP地址

[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.查看主机FQDN

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

4.查看短主机名

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

五、hostnamectl的使用

1.查看主机详细信息

[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.设置主机名

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

3.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
相关文章
|
1天前
|
安全 网络协议 Linux
linux必学的60个命令
Linux是一个功能强大的操作系统,提供了许多常用的命令行工具,用于管理文件、目录、进程、网络和系统配置等。以下是Linux必学的60个命令的概览,但请注意,这里可能无法列出所有命令的完整语法和选项,仅作为参考
|
1天前
|
监控 Linux 数据处理
|
1天前
|
编解码 Ubuntu Linux
|
1天前
|
Linux
|
1天前
|
Linux
请问如何在Linux系统中删除一个磁盘分区
请问如何在Linux系统中删除一个磁盘分区
|
1天前
|
Linux
Linux系统的磁盘管理
Linux系统的磁盘管理
|
1天前
|
JSON Linux 数据格式
Linux命令发送http
请注意,`curl`命令非常灵活,可以根据您的需求进行多种配置和自定义。您可以查看 `curl`命令的文档以获取更多详细信息。
4 0
|
1天前
|
Unix Linux Shell
Linux系统使用超详细(一)
Linux系统是一种开源的、类Unix操作系统内核的实现,它基于Unix的设计原理和思想,并在全球范围内广泛应用。以下是对Linux系统的详细描述:
|
2天前
|
Ubuntu Linux 编译器
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤