Ubuntu 20.04 LTS change hostname permanently

栏目: IT技术 · 发布时间: 4年前

内容简介:file. Open the Terminal application and type the following commands to set or change the hostname or computer name on Ubuntu.The procedure to change the computer name on Ubuntu 20.04 LTS:

I am a brand-new Ubuntu Linux 20.04 LTS VM user. By default, my server name to ‘localhost’ during cloud installation, but now I would like to change the computer name to ‘ubuntu-2004-nixcraft’. Can you tell me how do I remove the localhost and set it to ubuntu-2004-nixcraft on Ubuntu 20.04 Linux? How do I change the Ubuntu computer name from ‘localhost’ to ‘ubuntu-2004-nixcraft’? Can you tell me more about Ubuntu Linux change hostname command?

One can use the hostnamectl command to view or set the Ubuntu 20.04 LTS server’s host name. The host name or computer name is usually at system startup in /etc/hostname

file. Open the Terminal application and type the following commands to set or change the hostname or computer name on Ubuntu.

How to display the current Ubuntu hostname

Run the following command:

hostnamectl

Of course, you can use the echo command/printf command to print hostname too:

echo "$HOSTNAME"
printf "%s\n" $HOSTNAME
hostname
Ubuntu 20.04 LTS change hostname permanently

Finally, try thecat command on /etc/hostname

cat /etc/hostname

Ubuntu 20.04 LTS change hostname permanently

The procedure to change the computer name on Ubuntu 20.04 LTS:

  1. Type the hostnamectl command :
    sudo hostnamectl set-hostname newNameHere
    Delete the old name and setup new name.
  2. Next Edit the /etc/hosts file:
    sudo nano /etc/hosts
    Replace any occurrence of the existing computer name with your new hostname.
  3. Reboot the system to changes take effect:
    sudo reboot

How to change hostname on Ubuntu 20.04 without a system restart

Let us view current computer name setting, just type the following command:

hostnamectl

Next change hostname from localhost to ubuntu-2004-nixcraft, enter:

sudo hostnamectl set-hostname ubuntu-2004-nixcraft

Verify new changes:

hostnamectl
Ubuntu 20.04 LTS change hostname permanently

Find your public or private IP address by running theip command:

ip a

ip a s eth0
12: eth0@if13: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:24:b3:08 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.105.28.43/24 brd 10.105.28.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fe24:b308/64 scope link 
       valid_lft forever preferred_lft forever

Update /etc/hosts file with that IP address such as 10.105.28.43 using a text editor such as vim command/nano command:

$ sudo vi /etc/hosts

OR

$ sudo nano /etc/hosts

Update/append:

10.105.28.43 ubuntu-2004-nixcraft

Make sure you replace all occurrence of the old computer name with your new one too. Save and close the file in vim .

Conclusion

You learned how to change hostname permanently when using Ubuntu 20.04 LTS server or desktop computer as per your project needs.

This entry is 17 of 17 in the Linux/Unix Set hostname Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Change Hostname (computer name)
  2. Debian Linux: Change Hostname / Computer Name Permanently
  3. Linux change my hostname / computer system name
  4. Linux Change Hostname
  5. RHEL / Centos Linux 7: Change and Set Hostname Command
  6. OpenBSD Change Hostname
  7. CentOS Linux 5/6 Change Hostname Command
  8. Linux setting hostname and domain name of my server
  9. FreeBSD Change Hostname without reboot
  10. SuSe Linux Change Hostname without reboot
  11. How to set the hostname on Fedora Linux
  12. Ubuntu 18.04 LTS change hostname permanently
  13. Ubuntu set hostname permanently (computer name) command
  14. OpenSUSE Linux set hostname permanently (computer name) command
  15. RHEL 8 Linux set hostname permanently (computer name) command
  16. CentOS 8 Linux set hostname permanently (computer name) command
  17. Ubuntu 20.04 LTS set hostname permanently (computer name) command

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

一目了然

一目了然

Robert Hoekman, Jr. / 段江玲 / 机械工业出版社华章公司 / 2012-3-19 / 59.00元

可用性或易用性是软件或Web设计师的重要设计目标之一。本书深入阐述了如何设计出简单易用的基于Web的软件,以帮助读者理解、掌握显性设计的精髓。作者从软件开发初期谈起,一直到软件设计后期,分析诸多案例并论证了自己的见解或设计原则。本书在第1版的基础上进行了重大改进,尤其是在设计思想上,作者在本书中谈到“以用户为中心的设计”、“以任务为中心的设计”以及“以情景为中心的设计”的理念。这种设计理念也将更直......一起来看看 《一目了然》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器