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. LeetCode 5073. 进击的骑士(Java)BFS

    题目:5073. 进击的骑士 一个坐标可以从 -infinity 延伸到 +infinity 的 无限大的 棋盘上,你的 骑士 驻扎在坐标为 [0, 0] 的方格里. 骑士的走法和中国象棋中的马相似, ...

  2. 去除Chrome“请停用以开发者模式运行的扩展程序”提示

    将version.dll放在chrome同级目录,重启浏览器( 79.0.3945.79版本后已失效)                    

  3. 【数据结构】12.java源码关于ConcurrentHashMap

    目录 1.ConcurrentMap的内部结构 2.ConcurrentMap构造函数 3.元素新增策略4.元素删除5.元素修改和查找6.特殊操作7.扩容8.总结 1.ConcurrentMap内部结 ...

  4. Python-MySQL学习

    内容来源(有删改):https://blog.csdn.net/hzw6991/article/details/87893761 上面链接同步视频地址:https://www.bilibili.com ...

  5. ubuntu 安装和配置 GitLab

    一.概述 GitLab 是一个基于 Web 的开源 Git 软件仓库管理器,用 Ruby 编写,包括 wiki,问题管理,代码审查,监控以及持续集成和部署.它使开发人员能够创建,审查和部署他们的项目. ...

  6. [cf 997 E] Good Subsegments

    (这是石神找到的一道hiao题.) 题意: 你有一个长度为n的排列,有Q组询问$[l,r]$,每次询问$[l,r]$的子区间中有多少是好的. 一个区间是好的区间当且仅当该区间中的元素在排序后是连续的. ...

  7. 【简解】SP7556 Stock Charts

    题目大意 给出一个折线图,有N条线段,你想要把这些线段分成几个集合,使得每个集合中任意两条线段不相交. 求最少集合数. 分析 喵帕斯:以下提及的所有折线均指横坐标在\([1,k]\)里的折线段. 思考 ...

  8. vim安装 YCM 过程记录

    YCM(YouComplateMe) 属于Vim中大神级的插件,提供了类似于巨硬爸爸的VS中的代码补全,但是其安装方式也是比较复杂,因此特意写下一篇记录,记录下我自己如何安装这一插件的过程: 检查自己 ...

  9. nrm的安装和使用

    1.安装nodejs,下载地址,http://nodejs.cn/download/,安装过程直接点击下一步即可 安装完成后cmd输入npm -v 查看当前安装的npm的版本,如下图提示所示则表示安装 ...

  10. Linux中解压、压缩 ZIP文件

    解压 unzip -o -d /home/v-gazh myfile.zip # 把myfile.zip文件解压到 /home/v-gazh/ # -o:不提示的情况下覆盖文件: # -d:-d /h ...