Linux hostname and domain

Linux hostname and domain

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 that port is already in use

What are hostname and domain name doing in linux system?

I just yet starting to learn about web serving. So, far I know domain name is used for web page addresses (URL), like if we have an URL like this:

http://www.theaddress.thedomain.com/path/to/file.html 
  • http:// is for protocol that is being used.
  • www is for hostname.
  • theaddress.thedomain.com is for domain name.
  • and so on.

But I confused when those terms are used in linux system. Like, when I try to install Apache2 on VirtualMachine and use it as server, i still can’t use the hostname instead of typing my VM IP address to the web browser.

What are they doing in the system? Are those things matter when we don’t use the linux as a web server? And is it possible to address the VirtualMachine with it’s hostname and domain name? Or, those two only will be used when the server is going online?

everything has an ip address. the public internet has DNS resolving all the ip address to FQDN. Your local network can have that as some below mentioned. if it does they work the same

2 Answers 2

You would normally have to run a DNS server to get a domain name, which normally is not done for a personal VM. You can use the IP address of the VM to connect to it from inside your LAN, or localhost to connect to itself from within you VM. If you really want to, you can edit your hosts file on your box (not in the VM, but in the OS that is running the VM) to contain a custom hostname for your VM, basically, it’ll map the hostname to the IP of the VM.

Читайте также:  Swap space size linux

Without making things too complicated, your initial assumptions are correct.

You can give Machine-A a domain name but other machines on the network still need «someone» to translate that name into an IP if you try to ping it, most of the times that «someone» is the DNS server. Services exist to make this discovery automatic, i.e. let your machine broadcast it’s hostname through a specific protocol but let’s leave that aside for now.

In the case of a VM, another thing to remember is that VirtualBox for example will automatically put your VM in a LAN network, so by default your host machine is in a different network than your VM.

If you are playing with Apache inside a VM I suggest setting the network type of the VM to «bridged», that will allow it to behave like another machine on your same home network.

Regarding how to reach the VM from the host or any other machine in the same network (provided you’ve already set the bridged networking), you can register it in your home router, most of them will offer an option on their admin console to register hostnames.

Источник

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 основы

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 boot SPYRUS WorkSafe Pro Linux2Go drive
  • Hyperthreading in HPUX
  • How to list YUM repositories in RHEL / CentOS
  • How to configure proxy for YUM in RHEL, CentOS ?
  • Execute command at shutdown and boot in Suse Linux
  • How to install patch/software in HPUX
  • How to restart inetd service in Linux
  • Howto get Disk serial number in HPUX
  • 5 steps guide for SMTP configuration in Linux
  • How to disable IPv6 on Linux
  • Troubleshooting AWS cross-account IAM role access
  • How to move /tmp on a separate disk as a separate mount point

Источник

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