- Linux hostname command
- Description
- Syntax
- Options
- The FQDN
- Files
- Examples
- Related commands
- How to set/change FQDN on Ubuntu 20.04 Linux
- Viewing hostname including FQDN
- The /etc/hostname file
- Setting or changing FAQDN on Ubuntu 20.04 LTS per interface (advanced config)
- Set or change FQDN ( domain name ) on Ubuntu 20.04 Focal Fossa Linux
- Setting the Hostname (FQDN) in Linux Servers
- CentOS / Fedora
- Slackware
- Gentoo
- Arch Linux
- Update /etc/hosts
- Как установить доменное имя в GNU /Linux?
- 3 ответа
- Установить FQDN
- активировать имя хоста
- добавить имя домена и адрес на сервер
- VERIFY
- Linux Hosting: What is the purpose of setting hostname/FQDN in hosts file?
- 1 Answer 1
- Host file vs. DNS
- Hostname vs. FQDN
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. |
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.
Related commands
hostid — Print the numeric identifier for the current host.
uname — Print information about the current system.
Источник
How to set/change FQDN on Ubuntu 20.04 Linux
Viewing hostname including FQDN
The hostname command and hostnamectl command shows the Ubuntu system’s fully qualified host name including FQDN. Open the terminal application and then type:
$ hostname
nixcraft-wks01.sweet.home
$ hostnamectl status
The /etc/hostname file
A static hostname for the Ubuntu box is always set in the /etc/hostname file. Use the cat command to display it:
$ cat /etc/hostname
Of course, we can use a text editor to modify the file. For example:
$ sudo vim /etc/hostname
## OR ##
$ sudo nano /etc/hostname
Setting or changing FAQDN on Ubuntu 20.04 LTS per interface (advanced config)
However, the recommended way is to use the hostnamectl command to edit/etc/hostname file. The syntax is:
$ sudo hostnamectl set-hostname only-host
$ hostnamectl set-hostname host.your-fqdn-here
$ hostnamectl set-hostname server1.cyberciti.biz
Verify it:
$ hostnamectl status
# Show the Ubuntu system’s DNS domain name #
$ dnsdomainname
Please note that if /etc/hostname file does not exist on Ubuntu Linux, the host name is set by a reverse DNS query when the network interface gets an IP address assigned.
- 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
Join Patreon ➔
Set or change FQDN ( domain name ) on Ubuntu 20.04 Focal Fossa Linux
You can set or change the system FQDN using network interface config file too. For example, here is config for my eth0 interface:
# cat /etc/systemd/network/010-eth0.network
Источник
Setting the Hostname (FQDN) in Linux Servers
Here we will show how to set your system’s hostname and fully qualified domain name (FQDN). Your hostname should be something unique. Some people name their servers after planets, philosophers, or animals. Note that the system’s hostname has no relationship to websites or email services hosted on it, aside from providing a name for the system itself. Your hostname should not be «www» or anything too generic.
CentOS / Fedora
Enter the following commands to set the hostname, replacing myservername with the hostname of your choice:
Slackware
Enter the following commands to set the hostname, replacing myservername with the hostname of your choice:
Gentoo
Enter the following commands to set the hostname, replacing myservername with the hostname of your choice:
Arch Linux
Edit your /etc/rc.conf to configure the hostname for your system. Be sure to replace myservername with the hostname of your choice:
File excerpt:/etc/rc.conf
Issue the following command to set the hostname, replacing myservername with the hostname of your choice:
Update /etc/hosts
Next, edit your /etc/hosts file to resemble the following example, replacing myservername with your chosen hostname, example.com with your system’s domain name, and 12.34.56.78 with your system’s IP address. As with the hostname, the domain name part of your FQDN does not necesarily need to have any relationship to websites or other services hosted on the server (although it may if you wish). As an example, you might host «www.something.com» on your server, but the system’s FQDN might be «mars.somethingelse.com.»
File:/etc/hosts
If you have IPv6 enabled on your Linode, you will also want to add an entry for your IPv6 address, as shown in this example:
File:/etc/hosts
The value you assign as your system’s FQDN should have an «A» record in DNS pointing to your Linode’s IPv4 address. For Linodes with IPv6 enabled, you should also set up a «AAAA» record in DNS pointing to your Linode’s IPv6 address.
Источник
Как установить доменное имя в 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 Hosting: What is the purpose of setting hostname/FQDN in hosts file?
I just bought a Linode VPS hosting plan and was following this guide to set up. In the «Setting the Hostname» section and «Update /etc/hosts » section, it says the FQDN/hostname to be set here does not need to be related with the websites I am about to host, which makes me confused.
I did my own research by reading lots of articles but am still not very sure what role the hostname/FQDN is playing in my web hosting business. Here are some basic facts I’ve managed to find out, feel free to correct me if anything wrong:
- FQDN must be something like xxx.somedomain.com, if «xxx.» is omitted then it is not a FQDN.
- the xxx , which I think could be loosely called a subdomain, can also be referred to as «hostname», according to https://kb.iu.edu/d/aiuv.
In my local machine, by adding the following line to the hosts file
63.117.14.58 www.yahoo.com whatever
every network requests for «www.yahoo.com» or «whatever» will be redirected to IP address 63.117.14.58(which is google.com’s IP). It is a way to block unwanted sites in local machine.
Now the tutorial suggests adding this line to the «hosts» file in my server
It mentions that in the above line, domain name may or may not be the domain I am about to host, but the hostname should be the one I have already set during previous steps. My questions are:
1)Based on Facts#3, I think this line redirects any requests on the server for myhostname.anything.com or myhostname to my IP address, but what does this mean? Shouldn’t any request for myhostname.anything.com from a user’s computer already be translated to a certain IP address(Be it or not my IP address)? Why do I have to redirect it on my server? My understanding about how a HTTP request works is when user type in the domain name into the browser, the browser will contact the domain server, and the domain server will direct it to a DNS server based on the domain’s DNS record, and then the DNS server will resolve the IP address, and then browser fetch data from that IP address. This procedure of my understanding seems having nothing to do with the «hosts» file on my server.
2) A.In regards of the FQDN, why the hostname has to be same with the hostname I set on my server and the domain name doesn’t?
B.What will happen if I do set a different hostname here?
C.And what is the purpose to set or not set my domain name as the FQDN here?
D.And what will happen if I only set a FQDN but not the hostname? like this
Lots of questions but I believe the answers to some of them are overlapped, and overall I think the big question is «What part does setting hostname/editting hosts file play in my webhosting business?»
Thank you for your time in advance.
1 Answer 1
It’s going to be rough for people to answer this question because it starts with a simpler premise and proceeds to go down a deep rabbit hole from there. Let’s start from the beginning.
Host file vs. DNS
I don’t think this needs much explanation, so I’ll keep it brief. The purpose of the hosts file is to define host to IP address mappings that do not rely upon DNS. The most important of these for a server is the device’s own name, because it’s silly for a problem with your DNS server to prevent your device from being able to refer to itself by name.
So long as we’re only using host files, we don’t need to use domains at all. DNS isn’t involved, so who cares? Unfortunately as our network grows, it becomes less sustainable to have each device independently tracking the name of all devices on our network. That leads us to using DNS, and introduces some new logistical hurdles.
Hostname vs. FQDN
Hostnames are device names, or node names if you prefer. It’s a uniquely identifying name that is meaningful to the device owner, and not necessarily meaningful or even exposed to people consuming the services on the device. This is what Linode means when it says that the name doesn’t need to have anything to do with the services that you’re hosting.
For example, let’s say you own a company named Contoso, and you operate a website called example.com . The website is hosted on six machines, named dalek01 through dalek06 . All the outside world needs to know is that they can get the website they want if they plug www.example.com into their web browser. Overly inquisitive Time Lords need not concern themselves with the fact that their request for www.example.com was serviced by dalek03 .
By itself, a hostname doesn’t necessarily have anything to do with DNS at all. It’s just the name of the device, and it doesn’t even necessarily have a domain suffix associated with it. So far it’s simple!
Now we make things a little trickier. Story time!
Источник