Как узнать host linux

Как узнать host linux

NAME

hostname - show or set the system's host name domainname - show or set the system's NIS/YP domain name ypdomainname - show or set the system's NIS/YP domain name nisdomainname - show or set the system's NIS/YP domain name dnsdomainname - show the system's DNS domain name

SYNOPSIS

hostname [-a|--alias] [-d|--domain] [-f|--fqdn|--long] [-A|--all-fqdns] [-i|--ip-address] [-I|--all-ip-addresses] [-s|--short] [-y|--yp|--nis] hostname [-b|--boot] [-F|--file filename] [hostname] hostname [-h|--help] [-V|--version] domainname [nisdomain] [-F file] ypdomainname [nisdomain] [-F file] nisdomainname [nisdomain] [-F file] dnsdomainname 

DESCRIPTION

Hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name. GET NAME When called without any arguments, the program displays the current names: hostname will print the name of the system as returned by the gethostname(2) function. domainname will print the NIS domainname of the system. domainname uses the gethostname(2) function, while ypdomainname and nisdomainname use the yp_get_default_domain(3). dnsdomainname will print the domain part of the FQDN (Fully Qualified Domain Name). The complete FQDN of the system is returned with hostname --fqdn (but see the warnings in section THE FQDN below). SET NAME When called with one argument or with the --file option, the commands set the host name or the NIS/YP domain name. hostname uses the sethostname(2) function, while all of the three domainname, ypdomainname and nisdomainname use setdomainname(2). Note, that this is effective only until the next reboot. Edit /etc/hostname for permanent change. Note, that only the super-user can change the names. It is not possible to set the FQDN or the DNS domain name with the dnsdomainname command (see THE FQDN below). The host name is usually set once at system startup in /etc/init.d/hostname.sh (normally by reading the contents of a file which contains the host name, e.g. /etc/hostname). THE FQDN The FQDN (Fully Qualified Domain Name) of the system is the name that the resolver(3) returns for the host name, such as, ursula.example.com. It is usually the hostname followed by the DNS domain name (the part after the first dot). You can check the FQDN using hostname --fqdn or the domain name using dnsdomainname. You cannot change the FQDN with hostname or dnsdomainname. The recommended method of setting the FQDN is to make the hostname be an alias for the fully qualified name using /etc/hosts, DNS, or NIS. For example, if the hostname was "ursula", one might have a line in /etc/hosts which reads 127.0.1.1 ursula.example.com ursula Technically: The FQDN is the name getaddrinfo(3) returns for the host name returned by gethostname(2). The DNS domain name is the part after the first dot. Therefore it depends on the configuration of the resolver (usually in /etc/host.conf) how you can change it. Usually the hosts file is parsed before DNS or NIS, so it is most common to change the FQDN in /etc/hosts. If a machine has multiple network interfaces/addresses or is used in a mobile environment, then it may either have multiple FQDNs/domain names or none at all. Therefore avoid using hostname --fqdn, hostname --domain and dnsdomainname. hostname --ip-address is subject to the same limitations so it should be avoided as well.

OPTIONS

-a, --alias Display the alias name of the host (if used). This option is deprecated and should not be used anymore. -A, --all-fqdns Displays all FQDNs of the machine. This option enumerates all configured network addresses on all configured network interfaces, and translates them to DNS domain names. Addresses that cannot be translated (i.e. because they do not have an appropriate reverse IP entry) are skipped. Note that different addresses may resolve to the same name, therefore the output may contain duplicate entries. Do not make any assumptions about the order of the output. -b, --boot Always set a hostname; this allows the file specified by -F to be non-existant or empty, in which case the default hostname localhost will be used if none is yet set. -d, --domain Display the name of the DNS domain. Don't use the command domainname to get the DNS domain name because it will show the NIS domain name and not the DNS domain name. Use dnsdomainname instead. See the warnings in section THE FQDN above, and avoid using this option. -f, --fqdn, --long Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a short host name and the DNS domain name. Unless you are using bind or NIS for host lookups you can change the FQDN and the DNS domain name (which is part of the FQDN) in the /etc/hosts file. See the warnings in section THE FQDN above und use hostname --all- fqdns instead wherever possible. -F, --file filename Read the host name from the specified file. Comments (lines starting with a `#') are ignored. -i, --ip-address Display the network address(es) of the host name. Note that this works only if the host name can be resolved. Avoid using this option; use hostname --all-ip-addresses instead. -I, --all-ip-addresses Display all network addresses of the host. This option enumerates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option does not depend on name resolution. Do not make any assumptions about the order of the output. -s, --short Display the short host name. This is the host name cut at the first dot. -V, --version Print version information on standard output and exit successfully. -y, --yp, --nis Display the NIS domain name. If a parameter is given (or --file name ) then root can also set a new NIS domain. -h, --help Print a usage message and exit.

NOTES

FILES

/etc/hostname Historically this file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software is able to cope with a full FQDN here. This file is read at boot time by the system initialization scripts to set the hostname. /etc/hosts Usually, this is where one sets the domain name by aliasing the host name to the FQDN.

AUTHORS

Peter Tobias, tobias@et-inf.fho-emden.de> Bernd Eckenfels, net-tools@lina.inka.de> (NIS and manpage). Michael Meskes, meskes@debian.org>

Источник

Читайте также:  Linux error 1045 access denied

hostname в CentOS

Изображение баннера

Имя хоста — это уникальная метка, которая идентифицирует машину в сети.

Должна существовать таблица соответствия между hostname и IP адресом это нужно для для маршрутизации пакетов.

Хост может иметь несколько имён, но предпочтительным является вариант, когда имя одно.

Существует три класса hostname : static , pretty и transient .

  • static — традиционное имя хоста, которое может быть установлено пользователем и хранится в /etc/hostname
  • pretty — имя хоста UTF8 в свободной форме, используемое для представления пользователю. Например HeiHei’ host.
  • transient — динамическое имя хоста, поддерживаемое ядром, которое может быть изменено сервером DHCP или mDNS во время выполнения. По умолчанию это то же самое, что и static имя хоста.

Рекомендуется использовать полное доменное имя ( FQDN ) как для static и для transient имен, таких как host.example.com .

Так как CentOS 7 поддреживает только Fully Qualified Domain Names (FQDNs), советую тщательно проверить hostname, который вы планируете использовать.

  • Строчные буквы от a до z
  • Цифры от 0 до 9
  • Точки и дефисы
  • Hostnames может быть от 2 до 63 символов
  • Hostnames должен начинаться и заканчиваться цифрой или буквой

Узнать имя своего хоста

Существует несоколько способов узнать имя своего хоста.

Часто для этого достаточно просто посмотреть в терминал

[andrei@ localhost Downloads]$

andrei — это имя пользователя

Downloads — имя текущей директории

Посмотреть порядок можно выполнив

W — Working Directory — Рабочая диретория

Static hostname: localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: 35e254eda578c54084b96e06d5f285cf Boot ID: afb44fef8d764f30bb89550849b02fde Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1160.36.2.el7.x86_64

Изменить имя хоста

С помощью команды hostname

hostname dns-server
hostname

Если заново открыть терминал изменения будут видны в командной строке.

Читайте также:  At commands huawei linux

Это имя хоста сохранится только до перезагрузки системы

Если выполнить hostnamectl видно, что помянелось только динамическое имя хоста

Static hostname: localhost.localdomain Transient hostname: dns-server Icon name: computer-vm Chassis: vm Machine ID: cff8a80b9c356243b5238452511a8ade Boot ID: 64d9ddab85ec4c219ac46c6a2940e628 Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1160.42.2.el7.x86_64 Architecture: x86-64

Если изучить файл hostname , также можно увдиеть отсутствие изменений.

С помощью hostnamectl

hostnamectl set-hostname dns-server.andrei.com
hostname

Это постоянное изменение. Т.е. новое имя хоста имеет класс persistent.

pretty name

Чтобы задать pretty name нужно воспользоваться кавычками

hostnamectl set-hostname «andrei’s.host.com»
hostnamectl

Static hostname: andreis.host.com Pretty hostname: andrei’s.host.com Icon name: computer-vm Chassis: vm Machine ID: cff8a80b9c356243b5238452511a8ade Boot ID: 64d9ddab85ec4c219ac46c6a2940e628 Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1160.42.2.el7.x86_64 Architecture: x86-64

Появилось pretty hostname а static hostname такое же , но без запрещенных символов

В /etc/hostname отображается только static hostname

pretty hostname можно увидеть в файле /etc/machine-info

hosts

Изучить информацию об именах других хостов можно в файле hosts

В моём примере в сети есть два хоста:

dns-server.andrei.com с IP адресом 192.168.56.149

host113.andrei.com с IP адресом 192.168.56.113

Зайдём на него с помощью ssh и посмотрим, есть ли у него записи об именах других хостов в сети.

Для наглядности я теперь буду показываеть приглашение терминала чтобы было видно имя хоста.

[andrei@ dns-server ~]$ ssh andrei@192.168.56.113

[andrei@ host113 ~]$ ping 192.168.56.149

PING 192.168.56.149 (192.168.56.149) 56(84) bytes of data. 64 bytes from 192.168.56.149: icmp_seq=1 ttl=64 time=0.650 ms 64 bytes from 192.168.56.149: icmp_seq=2 ttl=64 time=0.731 ms ^C — 192.168.56.149 ping statistics — 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 0.650/0.690/0.731/0.048 ms

Читайте также:  Анонимный серфинг linux mint

[andrei@ host113 ~]$ ping dns-server.andrei.com

ping: dns-server.andrei.com: Name or service not known

host113 не знает как разрешить имя dns-server.andrei.com

Это неудивительно — ведь в файле hosts нет про него никаких записей. Проверим содержимое:

[andrei@ host113 ~]$ cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

Добавим запись о dns-server.andrei.com

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.56.149 dns-server.andrei.com

[andrei@ host113 ~]$ ping dns-server.andrei.com

PING dns-server.andrei.com (192.168.56.149) 56(84) bytes of data. 64 bytes from dns-server.andrei.com (192.168.56.149): icmp_seq=1 ttl=64 time=0.698 ms 64 bytes from dns-server.andrei.com (192.168.56.149): icmp_seq=2 ttl=64 time=0.735 ms 64 bytes from dns-server.andrei.com (192.168.56.149): icmp_seq=3 ttl=64 time=0.739 ms ^C — dns-server.andrei.com ping statistics — 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.698/0.724/0.739/0.018 ms

alias

Чтобы не писать длинные имена хостов можно придумать alias

FQDN — Fully Qualified Domain Name — полностью определённое имя домена.

192.168.56.149 dns-server.andrei.com vbdns

[andrei@ host113 ~]$ ping vbdns

PING dns-server.andrei.com (192.168.56.149) 56(84) bytes of data. 64 bytes from dns-server.andrei.com (192.168.56.149): icmp_seq=1 ttl=64 time=0.619 ms 64 bytes from dns-server.andrei.com (192.168.56.149): icmp_seq=2 ttl=64 time=0.674 ms ^C — dns-server.andrei.com ping statistics — 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 0.619/0.646/0.674/0.037 ms

Обратите внимание на dns-server.andrei.com

Хоть пинг и был по алиасу, ответ идёт как от static fqdn

Если поменять порядок так, что vbdns идёт первым а FQDN dns-server.andrei.com вторым, но dns-server.andrei.com будет считаться алиасом

192.168.56.149 vbdns dns-server.andrei.com

В таком случае ответ будет идти от vbdns

[andrei@ host113 ~]$ ping vbdns

[andrei@ host113 ~]$ ping dns-server.andrei.com

PING vbdns (192.168.56.149) 56(84) bytes of data. 64 bytes from vbdns (192.168.56.149): icmp_seq=1 ttl=64 time=0.721 ms 64 bytes from vbdns (192.168.56.149): icmp_seq=2 ttl=64 time=1.01 ms ^C — vbdns ping statistics — 2 packets transmitted, 2 received, 0% packet loss, time 1004ms rtt min/avg/max/mdev = 0.721/0.866/1.012/0.148 ms

Это может стать важным при работе с сертификатами

Источник

Оцените статью
Adblock
detector