Linux get dns hostname

How to get a hostname/domain name from an IP address in Linux

One of the questions that many Linux users ask is how they can retrieve a system’s hostname using its IP address. It may seem an uphill task, but in the real sense, it’s quite easy. Essentially, this is known as the reverse DNS lookup. Reverse DNS lookup queries an IP address to retrieve the hostname or domain of the server. The exact opposite is the Forward DNS lookup which maps the domain name to the IP address.

In this short guide, we have explored a few ways to performs Reverse DNS lookup and get a domain name from an IP address. For demonstration purposes, I have used Ubuntu 20.04.

Prerequisites

Before you roll up your sleeves, ensure that your remote host has an A record which is a DNS entry that points or maps a domain name to an IP address

Perform DNS Reverse lookup using dig command

Dig command is a flexible and powerful tool that is used for querying or probing DNS records. It’s an acronym for domain information groper and allows you to retrieve a wide array of DNS information such as A, CNAME, MX, and SOA records.

Perform DNS Reverse lookup using nslookup command

A nslookup command is a troubleshooting tool that features highly in a sysadmin’s armory. It’s a versatile tool that performs all DNS record querying such as CNAME, A, MX, and reverses or PTR records.

To retrieve a domain name from an IP address, use the command syntax:

Perform DNS Reverse lookup using the host command

Similarly, you can use the host command to obtain a hostname or domain name from an IP address using the syntax as shown.

For example, to check the domain name for the IP 5.9.235.235, execute the command:

Just like the Nslookup command, you can also use the host command with hostnames or IP addresses.

Conclusion

The few examples that we have just elaborated are a sure way of helping you obtain the domain name from an IP address. Usually, the reverse DNS lookup is trivial and not as crucial as the forward lookup, which maps domain names to IP addresses. Your feedback or contribution will be highly welcomed.

Читайте также:  Запустить терминал от root astra linux

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

Источник

How To Find Hostname In Linux

A Hostname is an unique alphanumeric label assigned to a Linux system in order to identify it on the network. It can also contain a few special characters such as hyphen (-), period (.), and underscore (_). A typical hostname consists of up to 253 characters. Generally, the hostname is stored in /etc/hostname file in most Linux distributions. In this brief guide, we will learn about various commands to find hostname in Linux operating systems.

1. Find Hostname in Linux with hostname command

The hostname command is used to display a Linux system’s DNS name and Hostname. It also allows the users to change or set the Hostname.

To find Hostname in Linux, run hostname command without any options:

$ hostname ostechnix

Find Hostname in Linux with hostname command

As you see in the output, my Linux system’s hostanme is ostechnix.

If you want to show the FQDN (Fully Qualified Domain Name), run:

2. Display Hostname with hostnamectl command in Linux

The hostnamectl command is used to get and set the system hostname and related settings in Linux.

To display the hostname of your Linux machine, run hostnamectl command without any options:

Sample output:

Static hostname: ostechnix Icon name: computer-laptop Chassis: laptop Machine ID: 09bfdb996ad847c782739db185f3e634 Boot ID: 97d0b5bdeacd4f8e852a042c9228be74 Operating System: Ubuntu 20.04.1 LTS Kernel: Linux 5.4.0-62-generic Architecture: x86-64

Display Hostname with hostnamectl command in Linux

Unlike the hostname command, hostnamectl displays a few more details of your system such as type of the system (laptop or desktop), Boot & machine ID, Operating system and Kernel version, Architecture etc.

To display only the Hostname, use —static flag:

$ hostnamectl --static ostechnix

3. Check Linux Hostname with nmcli command

The nmcli is a command line tool to control NetworkManager and report the network status. With nmcli, we can create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

To check the hostame of a Linux system with nmcli tool, run this command:

$ nmcli general hostname ostechnix

4. View Hostname using uname command

The uname is a command line tool to print all system information such as hostname, Kernel release, Kernel version, operating system, and processor architecture etc.

To view hostname with uname command, run it with -n option:

$ uname -n ostechnix

5. Get Hostname by reading /etc/hostname file

As stated already, the hostname is stored in /etc/hostname file in most Linux distributions. To get the hostname of a Linux system, simply display the contents of /etc/hostname file:

$ cat /etc/hostname ostechnix

These are the most commonly used commands to find hostname in Linux. There are also a two uncommon ways to check Linux hostname. They have been given below for your reference.

Читайте также:  Restart iptables in linux

6. Print Hostname in Linux with sysctl command

The sysctl command is used to list and modify kernel parameters at runtime.

We can print a Linux system’s hostname using sysctl command line below:

$ sysctl kernel.hostname kernel.hostname = ostechnix

7. Determine Hostname in Linux with ProcFS

Proc file system (or shortly procfs) is a virtual file system maintained by the Linux kernel. It is also sometimes referred to as a process information pseudo-file system. It doesn’t contain ‘real’ files but runtime system information such as system memory, devices mounted, hardware configuration etc. All these information are available under a special directory named /proc in Linux.

To determine the hostname of Linux with prcfs, run:

$ cat /proc/sys/kernel/hostname ostechnix

You know now different methods to view a Linux system’s hostname. How will you change it? The following guide explains how to set a new hostname or change the existing hostname, either from command line or from Settings section in graphical mode.

Related read:

sk

Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India.

Источник

How To Get Host Name and Domain Name Of Linux?

Host name is the identifier of a system in the network. Host name can be get with different ways in Linux. Host name is generally put in the /etc/hostname file.

Get Host name By Echoing Host name File

Host name information is stored in a file /etc/hostname . So we can simple print the host name to the terminal with echo command like below.

Get Host name By Echoing Host name File

Get Host name With hostname Command

We can get host name with hostname command. This will only list host name and will not print domain related information.

Get Host name With host name Command

Get Fully Qualified Host name

We can get fully qualified host name which provides full name with domain information.

Get Fully Qualified Host name

Hostname File

Host name file /etc/hostname will only provide host name with fully qualified domain name. There will any no other data in this file.

Change Host name

As the hostname is stored in the /etc/hostname file we can change the hostname by editing this file. We will set the hostname as ubu1 with the following echo command. Keep in mind that in order to change /etc/hostname file we require root privileges which can be get with the sudo command.

$ sudo echo "ubu1" > /etc/hostname

Change Hostname

Get Domain Name

Domain name information is about the systems network configuration.

How To Get Host Name and Domain Name Of Linux? Infografic

Источник

How to Get Hostname/Domain Name from IP Address in Linux

get hostname domain name from ip address

Often new system administrators need to find a hostname or domain from a given IP address in Linux. It might seem like a difficult task but it quite easy. This process is called reverse DNS lookup. Generally, operating systems and browsers lookup IP address of a given domain name. This is called DNS lookup. In this article, we will cover how to do reverse DNS lookup. In other words, we will learn how to get hostname/domain name from IP address in Linux.

Читайте также:  Узнать чем занят файл linux

How to Get Hostname/Domain Name from IP Address in Linux

The most basic requirement is that the IP address you are targeting must, in fact, have a hostname/domain name. It is defined using an A Record that basically maps a hostname/domain name with the IP. It is generally defined with a domain registrar such as GoDaddy, Namecheap, etc. Once you have verified this, there are several tools you can use to do a reverse lookup on an IP address.

1. Using dig

Domain Information Groper (Dig) is a powerful tool that allows you to query DNS records. You can use it to obtain a wide range of information about an IP or domain, such as CNAME, A Record, MX and SOA records.

Here is the simple command to get hostname/domain name of an IP address. Replace with IP address whose hostname/domain name you want to find out.

Here is an example to get hostname/domain name of 54.43.32.21 using dig command.

$ dig -x 54.43.32.21 +noall +answer

If dig is not present on your system, run the following commands in your terminal to install dig on your system.

# Debian/Ubuntu systems $ apt update $ apt install dnsutils # RHEL/CentOS/SUSE $ sudo yum install bind-utils

2. Using NSLookup

You can also use nslookup command to fetch CNAME, A, MX, and other type of DNS querying. Here is the command to get hostname/domain name of host IP address.

Here is an example to get domain name of ip 54.43.32.21.

If nslookup is not present on your system, run the following commands in your terminal to install nslookup on your system.

# Debian/Ubuntu systems $ apt update $ apt install dnsutils # RHEL/CentOS/SUSE $ sudo yum install bind-utils

It is the same command as the one mentioned above to install dig, because bindutils and dnsutils install both dig and nslookup on your system.

3. Using Host Command

You can also use host command to get hostname/domain name form IP address. Here is the command to get hostname/domain name using host command.

Here is an example to get hostname/domain name from IP address 54.43.32.21.

Again, if you don’t have host command on your system, you need to install dnsutils on Debian/Ubuntu , and bind-utils on RHEL/CentOS/SUSE systems.

# Debian/Ubuntu systems $ apt update $ apt install dnsutils # RHEL/CentOS/SUSE $ sudo yum install bind-utils

In this article, we have learnt how to do reverse DNS lookup in Linux using dig, nslookup and host commands to get hostname/domain name from IP address in Linux. It is important to note that you can also use these commands for forward DNS lookups also, where you find out the IP address of a hostname/domain name. Each of these commands provides many useful options to customize your tasks. You can refer to their man documentation for this purpose.

Источник

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