Debian Changing Hostname

Chưa phân loại

The Hostname

The hostname is the label assigned to a device on a network – a desktop computer, database server, tablet pc, wifi router, or smartphone. This name is used to distinguish the devices from each another on a specific network or over the internet.

Mostly, the chosen name is human-readable, and has to be unique among the other machines in the local network. Hostnames must not contain a space since they can only contain letters, digits and a hyphen.

In institutions with a large number of users like universities it is quite common to name a computer after fruits, favourite places, greek letters, geographical regions, or musical instruments. For private networks there are no name conventions to be followed, and hostnames like “FamiliyPC”, “dads-tablet”, or “printer” can be found.

The computer’s hostname is set initially during the installation, and stored in the file “/etc/hostname”. The screenshot below is taken from the graphical setup of Debian GNU/Linux 9, and uses the label “debian95” as a hostname referring to the release of Debian GNU/Linux 9.5.

As soon as your computer starts several services are initialized. This also includes the network, and the hostname, which can be used to address the device from then onwards. Using the UNIX command “hostname” reveals its name as follows:

$ hostname

More information can be retrieved using the command hostnamectl as follows:

$ hostnamectl
Static hostname: debian95
Icon name: computer-laptop
Chassis: laptop
Machine ID: 7c61402c22bf4cf2a9fcb28a4210da0b
Boot ID: 6e8ca49158ff4bc4afaa26763f42793b
Operating System: Debian GNU/Linux 8 (jessie)
Kernel: Linux 3.16.0-4-amd64
Architecture: x86-64

The hostname plus domain name result in the fully qualified domain name (FQDN) [1] that is needed to identify a computer without fail. In order to get the FQDN of the device use the switch “-f” (short for “–fqdn” or “–long”), instead:

$ hostname -f

Changing The Hostname

At first sight, changing the hostname (or renaming a computer) is comparably easy and takes a few minutes, only. It can be done in the following ways:

  • temporary change (valid until reboot) open a terminal window, change to user root, and invoke the command “hostname” followed by the new hostname:
    # hostname cucumber
    # hostname
  • permanent change open the file “/etc/hostname” with a text editor as user “root”, change the hostname, and save the file
  • permanent change for users of systemd open a terminal window, change to user root, and invoke the command “hostnamectl” as follows:
    # hostnamectl set-hostname cucumber

    The picture below illustrates this step using “hostnamectl”.

Being aware of side-effects

Still, it is half of the story. The file “/etc/hostname” is not the only place in which programs on your computer store the hostname. Using the “grep” command we find out which other files are affected, and need to be adjusted. The command below shows this for the hostname “debian95”:

# grep –color -l -r debian95 /*


The file “/etc/hosts” is essential for networking, and needs to be adjusted. Change “debian95” to “cucumber” to have the following result:

$ cat /etc/hosts localhost cucumber
# The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost
ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters $

Next, reload the network configuration as follows:

# invoke-rc.d start
# invoke-rc.d networking force-reload

In order to check your new network configuration you may ping your machine with the new hostname:

Et voila – it worked well. The final step is to check your applications according to the list above. The referring page in the Debian Wiki [2] gives you a good overview what to do with each application, and shall work as a reference guide for you.

Links and References

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Configure The Network on CentOS7

CentOS 7 uses Network Manager to manage the network. It is a great tool that makes configuring the network on CentOS easy....

How To Upgrade To Ubuntu 17.04 From Ubuntu 16.04LTS

Introduction to Ubuntu 17.04 Following the release of Ubuntu 17.04 (Zesty Zapus) on April 13, 2017, people want to know...

How to Generate Random Numbers in JavaScript

Does your next JavaScript project need a random number to work? Maybe you are creating a poker game for your site? To do...
Bài Viết

Bài Viết Mới Cập Nhật

Huớng dẫn dùng proxy cho ios, iphone 2023

Cách gắn set proxy cho điện thoại android, oppo, giả lập android, Ldplayer Bằng Proxydroid

Mua Proxy Socks5 VN Chơi Game Gia Lập Tăng Cường Trải Nghiệm Chơi Game

Mua Proxy Mỹ, Us Nuôi Tài Khoản Etsy, eBay Tìm Hiểu Về Mua Proxy Mỹ tại

Mua Proxy Game – Giải pháp tuyệt vời cho việc chơi game trên mạng mà không bị giới hạn về vị trí địa lý