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. Python pip版本升级

    pip版本升级命令: python -m pip install --upgrade pip 如果报错代码如下: (venv) C:\Users\ssdy\PycharmProjects\untitl ...

  2. 《Effective Objective-C》概念篇

    1.运行时 OC 语言由 Smalltalk(20世纪70年代出现的一种面向对象的语言) 演化而来,后者是消息型语言的鼻祖. OC 使用动态绑定的消息结构,在运行时检查对象类型. 使用消息结构的语言, ...

  3. HTML文件直接在浏览器打开和本地服务器localhost打开有什么区别?

    最直接的区别,很容易注意到,一个是file协议,另一个是http协议. file协议更多的是将该请求视为一个本地资源访问请求,和你使用资源管理器打开是一样的,是纯粹的请求本地文件. http请求方式则 ...

  4. git学习笔记 ---分支管理

    分支就是科幻电影里面的平行宇宙,当你正在电脑前努力学习Git的时候,另一个你正在另一个平行宇宙里努力学习SVN. 如果两个平行宇宙互不干扰,那对现在的你也没啥影响.不过,在某个时间点,两个平行宇宙合并 ...

  5. vscode入门使用教程(页面调试)

    初次使用vscode时各种不适应,所有需要用到的功能貌似都需要单独安装插件才能用.这让很多初次使用vscode的朋友有点无所适从. 下面本人就带各位朋友学习下如何使用vscode来进行最基本的工作—— ...

  6. property Alternative forms propretie

    property Alternative forms propretie English English Wikipedia has articles on: Property (disambigua ...

  7. 房地产propretie财产

    property 1. 财产:所有物(不可数); 地产, 房地产 He has a large property in the county. 他在这个县有一大宗地产. 1.Propretie obs ...

  8. mysql修改字符集问题

    mysql字符集问题: 本文主要解决mysql7以下问题:mysql7在默认安装后,关于数据库,表默认保存字符格式为latin1: 可以通过命令:查询当前mysql的编码设置: show variab ...

  9. 【RAC】将单实例备份集恢复为rac数据库

    [RAC]将单实例备份集恢复为rac数据库 一.1  BLOG文档结构图 一.2  前言部分 一.2.1  导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识, ...

  10. windows下控制台程序实现窗口显示

    windows下实现窗口显示,如果限定是C/C++语言,并且是原生Windows支持,需要使用GDI或GDI+.一般是在Visual Studio里新建Win32应用程序,而不是Win32 conso ...