Linux hostname with domain

How to change hostname with domainname on Debian/Ubuntu

Although it seems to be an FAQ, but I had never been able find a proper way to change hostname with domainname on Debian/Ubuntu. First of all, many «answers» or writings are just wrong by putting hostname with domainname (FQDN) into /etc/hostname , like this, this and this, because The Debian reference says the hostname should not use the FQDN:

3.5.5. The hostname The kernel maintains the system hostname. The init script in runlevel S which is symlinked to «/etc/init.d/hostname.sh» sets the system hostname at boot time (using the hostname command) to the name stored in «/etc/hostname«. This file should contain only the system hostname, not a fully qualified domain name.

» /etc/hosts Usually, this is where one sets the domain name by aliasing the host name to the FQDN.» and «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.»

$ cat /etc/hostname coral $ head -1 /etc/hosts 127.0.0.1 coral.my.domain.org localhost $ dnsdomainname ht.home $ cat /etc/resolv.conf domain ht.home search ht.home nameserver 192.168.0.1 # after I change it to -- $ cat /etc/resolv.conf # Fixed resolv.conf file domain my.domain.org search my.domain.org nameserver 192.168.0.1 # everything just gone wrong -- $ dnsdomainname dnsdomainname: No address associated with hostname $ hostname -f hostname: No address associated with hostname $ hostname -d hostname: No address associated with hostname 

Update I did a trace on hostname -f , and it seems the «No address associated with hostname» error comes from libresolv.so :

$ strace -o /tmp/strace.log hostname -f hostname: No address associated with hostname $ grep -E 'openat|close|No address' /tmp/strace.log openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 close(3) = 0 close(3) = 0 openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/etc/host.conf", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 3 close(3) = 0 close(3) = 0 close(3) = 0 write(2, "No address associated with hostn". 35) = 35 
$ uname -rm 5.10.0-6-amd64 x86_64 $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux bullseye/sid Release: testing Codename: bullseye 

Источник

How to set the domain name on GNU/Linux?

I want to change my domain name. I can use the domainname command, but is there a way to make it permanent across reboots? I think it can be configured in /etc/resolv.conf but this file is generally generated and I don’t know exactly the difference between search and domain directives. And at what time exactly the information there is passed to the domainname program to set the domain name?

Читайте также:  Установка драйверов linux centos

Do you have any ideas on that?

I’d like to be mostly compatible across distributions. So if if anyone has pointers on the different distributions flavours, I’d gladly accept them.

Every distribution does this differently. Which ones are you interested in? And did you read their documentation?

Mostly RedHat and Debian flavours. And I couldn’t find relevant information in the documentation. But perhaps I haven’t looked hard enough, I admit I don’t know exactly where in the documentation it could be (or even if it is in the docs).

That’s fair. In Red Hat’s documentation, it’s buried in an appendix. While in Debian’s it’s not buried in an appendix, but it is confusing.

@Michael This link on the debian mailing list is mostly useful, especially So to finally answer your question, you configure your FQDN wherever you want names resovled. If you want it in files on the box itself, then it goes in /etc/hosts. If you run your own name server like I do (I run dnsmasq for simplicity) then you only have to record the information in

On red hat 7 and derived systems you should use hostnamectl to set up the hostname. cyberciti.biz/faq/rhel-redhat-centos-7-change-hostname-command/…

3 Answers 3

Set FQDN

I’m using Debian 7 and this is what worked for me; thanks to Fernando Ribeiro.

server # here's where you put the server's host name 

activate hostname

add domain name and address to the server

192.168.1.2 server.domain server 

VERIFY

> hostname --short server > hostname --domain domain > hostname --fqdn server.domain > hostname --ip-address 192.168.1.2 

after changing server name in /etc/hostname you might not be able to edit /etc/hosts . In this case you have to use xauth add as stated in this answer stackoverflow.com/questions/20611783/…

When you use redhat-base systems, linux uses /etc/sysconfig/network file and you should set variable HOSTNAME to FQDN , when you use FQDN , linux itself determines domain name.

But when you use debian-base systems, you should fill /etc/hostname file with FQDN :

NOTE: if you want to set domain name be sure set FQDN (Fully Qualyfied Domain Name)

When you set, hostname -d shows you the domain name .

Thank you, but I was under the impression that these files should only contain the hostname without the domain part. If I do what you suggest, hostname will return the fqdn directly (no difference between hostname and hostname -f ).

Читайте также:  Linux how to display

oh by the way, i forget to say you should set hostname by hand hostname web.mydomain.com after configure your files. because when you configure your file memory can’t apply changes.(if it was useful, don’t forget useful flag)

man hostname , being cited from its end to beginning

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. 
 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. 

I’d say it does describe the whole thing thoroughly.

Источник

How to setup domain name in Linux server

Many companies have an internal domain for their IT infrastructure. This needs its servers to be configured with a domain name. This will ensure all servers will have FQDN (Fully Qualified Domain Name). For example, server12 is hostname and server12.kerneltalks.com is its FQDN. In such setup, many tools, monitoring requires servers to be identified by FQDN only.

Читайте также:  Linux find внутри файла

For such a scenario you have to configure the domain name for your Linux server. We will walk you through steps that need to be taken to the setup domain name on your Linux server.

First of all, check if your server is having domain name already set up or not using below command :

root@server12 # dnsdomainname kerneltalks.com

If you get output like above then your server is configured with the domain name. If your output is blank then you have to the setup domain name for your server.

Without further delay lets jump into steps to configure domain name.

Step 1.

How to setup FQDN in Linux?

First thing to be done is add FQDN to your hostname in /etc/hosts file.

root@server12 # cat /etc/hosts 10.10.2.32 server12.kerneltalks.com server12

To confirm your FQDN, run below command :

root@server12 # hostname -f server12.kerneltalks.com

Output should be hostname.domain name

Step 2.

Configure domain name in Red Hat RHEL, Fedora and CentOS

Add below line in /etc/sysconfig/network

Add below parameter in /etc/sysctl.conf

Configure domain name in Ubuntu

Edit your hostname (not FQDN) in /etc/hostname file. and restart hostname service. If you see below error :

# service hostname restart Failed to restart hostname.service: Unit hostname.service is masked.

you can set hostname using :

# hostnamectl set-hostname server12

Once done, confirm normal hostname (using hostname ) and FQDN (using hostname -f )

Step 3.

Add domain in /etc/resolv.conf . This file used for setting nameservers as well.

root@server12 # cat /etc/resolv.conf search kerneltalks.com

This addition makes sure that you can resolves hostnames within your domain.

Step 4.

Confirm that changes are working perfectly. Question is how to check the domain name of the Linux server?

Below are the commands to check hostname, FQDN, and domain name of your server.

root@server12 # hostname server12 root@server12 # hostname -f server12.kerneltalks.com root@server12 #dnsdomainname kerneltalks.com

hostname command shows your server’s hostname. hostname -f shows your FQDN. dnsdomainname command shows your domain name of the server!

  • How to move /tmp on a separate disk as a separate mount point
  • How to enable repository using subscription-manager in RHEL
  • How to configure nameserver in Linux
  • How to map Linux disk to vmware disk
  • 5 ways to check swap on Linux
  • How to list YUM repositories in RHEL / CentOS
  • Root disk mirroring in itanium HPUX
  • 4 steps guide for SMTP configuration in HPUX
  • How to resolve the MFA entity already exists error
  • How to upgrade kernel in RHEL, Suse, Ubuntu Linux
  • How to remount filesystem in the read-write mode under Linux
  • Hyperthreading in HPUX

Источник

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