Linux hostname multi domain

Linux hostname command

On Unix-like operating systems, the hostname command shows or sets the system hostname.

This page covers the GNU/Linux version of hostname.

Description

hostname is used to display the system’s DNS name, and to display or set its hostname or NIS (Network Information Services) domain name.

When called without any arguments, hostname displays the name of the system as returned by the gethostname function.

When called with one argument or with the —file option, hostname sets the system’s hostname using the sethostname function. Only the superuser can set the hostname.

The hostname is usually set once at system startup in the script /etc/init.d/hostname.sh normally by reading the contents of a file which contains the hostname, e.g., /etc/hostname.

Syntax

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 every FQDN 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 DNS 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 shows the NIS domain name and not the DNS domain name. Use dnsdomainname instead. See the warnings in the FQDN section, and avoid using this option if at all possible.
-f, —fqdn, —long Display the FQDN (fully qualified domain name). A FQDN consists of a short hostname and the DNS domain name. Unless you are using BIND (Berkeley Internet Name Domain) 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 the FQDN section, and avoid using this option if at all possible; use hostname —all-fqdns instead.
-F, —file file name Read the hostname from the specified file. Comments (lines starting with a `#‘) are ignored.
-i, —ip-address Display the network address(es) of the hostname. Note that this works only if the hostname can be resolved. Avoid using this option if at all possible; 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 hostname. This is the hostname cut at the first dot.
-v, —verbose Be verbose with all output.
-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 (the superuser) can also set a new NIS domain.
-h, —help Print a help message and exit.
Читайте также:  Как увидеть ubuntu с windows

The FQDN

The FQDN (fully qualified domain name) of the system is the name that the resolver returns for the hostname, such as mysubdomain.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 «mysubdomain«, one might have a line in /etc/hosts which reads:

Technically: The FQDN is the name getaddrinfo returns for the hostname returned by gethostname. 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.

Files

/etc/hostname Historically this file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software can 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 hostname to the FQDN.

Examples

Displays the system hostname.

hostid — Print the numeric identifier for the current host.
uname — Print information about the current system.

Источник

Как правильно установить имя хоста и доменное имя?

Я арендую сервер под управлением Ubuntu 16.04 в компании, назовем его company.org.

В настоящее время мой сервер настроен так:

  • Имя хоста: server737263
  • доменное имя: company.org

Вот мое полное доменное имя:

Это не удивительно.

Я также арендую доменное имя, давайте назовем его domain.org . Я хотел бы переименовать мой сервер в server1.domain.org .

Это означает настройку моего имени хоста как server1 и моего имени домена как domain.org .

Как я могу сделать это правильно?

Действительно, справочная страница для hostname не ясна. Для меня по крайней мере:

  • При вызове с одним аргументом или с параметром —file команды задают имя хоста или имя домена NIS / YP. hostname использует функцию sethostname (2), в то время как все три доменных имени, ypdomainname и nisdomainname используют setdomainname (2). Обратите внимание, что это действует только до следующей перезагрузки. Отредактируйте / etc / hostname для постоянного изменения.

Полное доменное имя

  • Вы не можете изменить полное доменное имя с именем хоста или dnsdomainname.

Так что кажется, что редактирования /etc/hostname недостаточно? Потому что если бы он действительно изменил имя хоста, он изменил бы полное доменное имя. Я также прочитал трюк, чтобы изменить имя хоста с помощью команды sysctl kernel.hostname=server1 , но ничто не говорит о том, правильный ли это путь или уродливый трюк.

Читайте также:  Intel gma 4500 driver windows 10

Как правильно установить имя хоста?

Как правильно установить доменное имя?

Источник

Как установить доменное имя в GNU /Linux?

Аналогично имени хоста, которое можно изменить по-разному:

  • временно используя команду hostname
  • с помощью /etc/hostname (или /etc/sysconfig/network или /etc/HOSTNAME , эти файлы используются сценариями инициализации)

Я хочу изменить свое доменное имя. Я могу использовать команду domainname , но есть ли способ сделать ее постоянной при перезагрузках? Я думаю, что его можно настроить в /etc/resolv.conf , но этот файл обычно генерируется, и я точно не знаю разницу между search и domain . И в какое время именно информация передается программе domainname для установки имени домена?

У вас есть идеи по этому поводу?

Я хотел бы быть в основном совместимым между дистрибутивами. Поэтому, если у кого-то есть указатели на разные дистрибутивы, я с радостью принимаю их.

3 ответа

Установить FQDN

Я использую Debian 7, и это то, что сработало для меня; благодаря Фернандо Рибейру .

sudoedit /etc /hostname

активировать имя хоста

sudo hostname -F /etc /hostname

добавить имя домена и адрес на сервер

VERIFY

Когда вы используете системы redhat-base , linux использует /etc/sysconfig/network , и вы должны установить переменную HOSTNAME в FQDN , когда вы используете FQDN , linux сам определяет имя домена.

Но когда вы используете системы debian-base , вы должны заполнить /etc/hostname с помощью FQDN :

ПРИМЕЧАНИЕ: , если вы хотите установить domain name обязательно установите FQDN (Полностью Qualyfied Domain Name)

Когда вы установите, hostname -d показывает вам domain name .

man hostname , процитированный от конца до начала

Я бы сказал, что он полностью описывает все это.

Источник

Linux setting hostname and domain name of my server

How to use hostnamectl command

If you are using systemd based distro such as RHEL/CentOS 7.x, Fedora latest, Ubuntu Linux 16.04 LTS, Debian 9.x+, Arch Linux and more, use hostnamectl command. To see current hostname, run:
$ hostnamectl
To change hostname to foo, run:
$ hostnamectl set-hostname ‘foo’
$ hostnamectl

A note about GUI tools

If you are using Red Hat or Fedora Linux (older version) use redhat-config-network GUI tool. Type following command and click on DNS tab > Setup hostname and domain name:
# redhat-config-network
On other hand you can edit a text file. Find out and set up the value for HOSTNAME in the file /etc/sysconfig/network:
# vi /etc/sysconfig/network
Setup/replace HOSTNAME
HOSTNAME=web.nixcraft.com
Where, web is hostname and nixcraft.com is your DNS domain name.

If you are using Debian Linux

You need to edit /etc/hostname file and put hostname.domain.com in this file:
# vi /etc/hostname
Set or replace hostname:
web.nixcraft.com

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard
Читайте также:  Как можно запустить windows без диска

Join Patreon

Debian, Suse and other Linux distro support GUI tool called network-admin. Type following command and click on DNS tab > Setup hostname and domain name:
$ network-admin

Please note that you must have properly configured DNS server to work FQDN based hostname. See how to configure Linux as a dns client.

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

thank you bro. it is really helpfull

I think we have to restart the network service after making the changes.

service network restart

Thank you so much for this information. It was very useful for me!

Do you also want to tell in your artice about restarting services so the new changes can come to effect? At the moment the article is half baked.

Thanks a lot from a CentOS newbie.

hi I want to learn linux .what step should i follow?

Step1: Change the New Values in the Host file
[root@erp

]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
192.168.0.1 erp.myappsdba.com erp
[root@erp

Step2: Change the New Values in the network file
[root@erp

]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=erp.myappsdba.com
GATEWAY=192.168.0.3

Step3: Change the New Values in the sysctl.conf and resolv.conf files
[root@erp

]## cat /etc/sysctl.conf
kernel.hostname=erp.myappsdba.com
kernel.domainname=myappsdba.com

[root@erp etc]# cat /etc/resolv.conf
search myappsdba.com
nameserver 192.168.0.7
nameserver 192.168.0.2
option attemts : 5
option timeout :15
[root@erp etc]#

Step4:Ping the Host Name or Changed IP Address.
[root@erp etc]# ping myappsdba.com
PING myappsdba.com (192.168.0.1) 56(84) bytes of data.
64 bytes from fortedc.myappsdba.com (192.168.0.1): icmp_seq=1 ttl=128 time=1.06 ms

Step5:Restart the Network or Reboot the system for effecting the changes
[root@erp

]# service network restart

Thanks for the good article. @Nilesh Thanks dude

Please help me connect to server with a Linux netbook. There is a box for the name of the server… but I don’t know it.

Источник

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