上次装完ubuntu后,今天想在ubuntu中安装VMware Tools,打开终端,发现自己的ubuntu的计算机名老长的一串,就像下面这图这样,看着让人不舒服,决定先把这个计算机名给改了。
![](https://i-blog.csdnimg.cn/blog_migrate/134d726c1396c68eff2b4ab187706e74.jpeg)
网上查资料,说是可以用hostname命令进行修改,hostname命令格式:
hostname <新计算机名>
-$sudo hostname linux
修改完后,打开新的终端窗口,显示修改成功,如下图所示:
![](https://i-blog.csdnimg.cn/blog_migrate/ac7934a596060b92278ca5e4fb81099d.jpeg)
重启ubuntu系统,发现刚刚修改的计算机名称没有保存。又变回没有修改前的计算机名了。
继续查找方法,说是修改/etc/hostname文件。方法如下:
-$sudo gedit /etc/hostname
输入密码后,进入文本编辑器,里面显示的内容如下图所示:
![](https://i-blog.csdnimg.cn/blog_migrate/ddff1e0dc2bbf1390814d713c01b2e75.jpeg)
修改它的内容为你自己想要设置的计算机名称,我把它设置成“linux”。然后重启,再打开终端,发现终端中已经更新了计算机名了。
听说只修改/etc/hostname迟早会出问题,至于会出什么问题,暂时还不知道,说是还需要继续修改/etc/hosts。所以打开/etc/hosts文件:
-$sudo gedit /etc/hosts
文件内容如下图所示:
![](https://i-blog.csdnimg.cn/blog_migrate/b41b971a886ca54ceeec0651c81d11ff.jpeg)
我把127.0.1.1中的名字也修改成了和/etc/hostname中一样的名字。
至此,修改计算机名字的操作完成。
修改计算机名的总结如下:
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
![](/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
![](https://blog.51cto.com/editor/icons/etc_01.gif)
转载于:https://blog.51cto.com/cynthia/648554