How To Find Hostname In Linux

1. How To Find Hostname In Linux

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

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:

$ hostname --fqdn

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:

$ hostnamectl

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

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

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

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

Get Hostname by reading /etc/hostname file

Supports mounting file system.

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.

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

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云满笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值