How to change hostname on Debian 10 Linux

last updated July 13, 2019 in CategoriesDebian / UbuntuLinux

How do I change the hostname of a Debian Linux 10 “Buster” operating system permanently using the command line tools?

You can use the hostnamectl command or hostname command to display or set the Debian Linux system’s host name. In this tutorial, you will learn how to change your hostname on Debian Linux.

Change hostname on Debian 10 Linux

  1. Login to your server: ssh user@server-name
  2. Become a root user using either sudo -s or su -
  3. To set the hostname to server1, run: hostnamectl set-hostname server1
  4. Edit the file /etc/hosts and update entries: vi /etc/hosts
  5. Verify it by running the hostnamectl command again.

Let us see all commands in details.

Display the current hostname for Debian Linux

Simply run the following command:
hostnamectl

The current hostname is set to localhost

Change the hostname on Debian 10

Now you know how to view the current hostname. It is time to change it as per your needs. A hostname is nothing but a name that identifies your Debian box on a network. Typically for the server, you set it as FQDN (fully qualified domain name) such as server1.cyberciti.biz. The syntax is as follows:
hostnamectl set-hostname {name-here}
For example, to change the system hostname to deb10.cyberciti.biz in Debian 10, you can use the following command:
sudo hostnamectl set-hostname deb10.cyberciti.biz
Next, edit the /etc/hosts file, run:
vi /etc/hosts
Find all references to oldname and replace with newname except for the following entries:

127.0.0.1	localhost

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

For example:

127.0.0.1	localhost
192.168.2.100 deb10.cyberciti.biz # The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Save and close the file.

Verify the change

How do you know that hostname was successfully changed? You use the same command without any arguments. In other words, type the following command:
hostnamectl

Set a particular pretty host name

The syntax is:
hostnamectl set-hostname "Vivek's Thinkpad" --pretty

Changing Debian host names remotely using ssh

From your Linux desktop, run:
hostnamectl set-hostname -H [username]@hostname
hostnamectl set-hostname {new_name_here} -H root@192.168.2.10
hostnamectl set-hostname www42.nixcraft.com -H root@192.168.2.10

The hostnamectl tool will use SSH to connect to the remote system. One can see help page by typing:
hostnamectl --help
Sample help page:

hostnamectl [OPTIONS...] COMMAND ...
 
Query or change system hostname.
 
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
 
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host
 
See the hostnamectl(1) man page for details.

Conclusion

On Debian Linux hostnamectl command used to query and change the system hostname and related settings. For more information see the man page here.

SHARE ON Facebook Twitter

How to change hostname on debian的更多相关文章

  1. How to change hostname on SLE

    修改/etc/HOSTNAME文件,在此文件中保存主机名,例如: linuxserv1 然后运行命令设置主机名 # /etc/rc.d/boot.localnet start 方法3. 运行 sysc ...

  2. Change hostname and IP on Soalris10

    To see the existing configuration: # ifconfig -a Update the following files for IP Address: /etc/hos ...

  3. bat 实现主机hostname的修改

    主机实现hostname的修改原理: 修改注册表中的值: hklm\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName 下的 Comp ...

  4. linux的hostname(主机名)修改详解

    Linux操作系统的hostname是一个kernel变量,可以通过hostname命令来查看本机的hostname.也可以直接cat /proc/sys/kernel/hostname查看. #ho ...

  5. Armbian hostname and WiFi configuration

    In previous post i have described installation of Armbian on Orange Pi PC Plus. Now is the time for ...

  6. Ubuntu Server 18.04 无法修改 hostname

    对于运维而言,我们希望每台服务器的 hostname 都能体现出它自己的功能/ip,方便排查. ubuntu server live 18.04 的安装流程非常友好,从 ip 到 hostname 都 ...

  7. Linux & change username & computer name & .bashrc

    Linux & change username & computer name ubuntu change username and computer name https://ask ...

  8. SIHA环境修改主机名实施步骤

    目 录 1 实施需求 2 修改主机名 2.1 停止HAS服务 2.2 修改主机名 3 重新配置服务 3.1 使用root用户重新配置CSS & OHAS服务 3.2 设置cssd自动启动属性 ...

  9. Centos6安装Gitlab

    安装参考 https://about.gitlab.com/downloads/ 可以从清华的镜像下载安装包, 注意区分自己用的是哪个发行版 https://mirror.tuna.tsinghua. ...

随机推荐

  1. Delphi RSA签名与验签【支持SHA1WithRSA(RSA1)、SHA256WithRSA(RSA2)和MD5WithRSA签名与验签】

    作者QQ:(648437169) 点击下载➨ RSA签名与验签 [delphi RSA签名与验签]支持3种方式签名与验签(SHA1WithRSA(RSA1).SHA256WithRSA(RSA2)和M ...

  2. vim 自定义设置

    修改系统配置(面对所有用户): root@bogon:~# cd /etc/vim/ root@bogon:/etc/vim# ls vimrc vimrc.tiny root@bogon:/etc/ ...

  3. 部署.Net Core APi+Vue 到 linux centos 服务器(一)

    部署.Net Core APi+Vue 到 linux centos 服务器(一) 前言:项目采用的是 .net core 作为接口,vue作为前端. 此时需要把整个项目架设到linux centos ...

  4. 向Spring 容器中注入对象的几种方法

    1.使用@Bean 注解,用于注入第三方 jar 包到SpringIOC容器中. 2.使用 @Import({Order.class, Member.class, MyImportBeanDefini ...

  5. C# vb .net实现锐化效果滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的锐化效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第一步 ...

  6. selenium中的元素操作之三大切换(二)

    一.窗口切换 使用方法: 1.获取到打开的所有的窗口,句柄handles all_handles = driver.window_handles print(all_handles) 2.获取当前的窗 ...

  7. Java调用Http/Https接口(2)--HttpURLConnection/HttpsURLConnection调用Http/Https接口

    HttpURLConnection是JDK自身提供的网络类,不需要引入额外的jar包.文中所使用到的软件版本:Java 1.8.0_191. 1.服务端 参见Java调用Http接口(1)--编写服务 ...

  8. SpringCloud中服务发现-Eureka

    1.Eureka服务端集群开发 1.先创建一个父工程 若是不是普通demo,还有别的配置时,需要注意若是服务开不起来可能就是父类依赖中可能会需要<dependencyManagement> ...

  9. tensorflow遇到ImportError: Could not find 'cudart64_100.dll'错误解决

    在安装tensorflow的时候,使用import tensorflow出现了找不到dll文件的错误,参考了很多博客和stackflow的解决方案,发现其中只说了版本号不匹配,但是没有具体说明什么样的 ...

  10. java自定义注释及其信息提取

    转自:https://xuwenjin666.iteye.com/blog/1637247 1. 自定义注解 import java.lang.annotation.Retention; import ...