当我连接到我的服务器(ubuntu server 10.10)时,我会看到这个:
如何移除“.belkin”?
name@server-name.belkin ~>
如何移除“.belkin”?
name@server-name.belkin ~>
/etc/hostname
并且
/etc/hosts
gksu gedit /path/to/file
sudo service hostname start
sudo service hostname restart
,主机名就可以在无需重启的情况下更改。 - Anthony O.status --system hostname
告诉我服务是存在的。所以,sudo service hostname restart
或者 sudo restart hostname
应该有效。你可能运行了 service hostname status
但找不到它。点击这里了解原因。 - user180409sudo service hostname restart
无效。我不得不进行完整的服务器重启。 - gerrytansudo service hostname start
(而不是restart),因为status --system hostname
返回hostname stop/waiting
。此外,当前终端没有显示新的主机名,我必须打开一个新的终端或shell才能看到它。 - user180409sudo hostname
命令,这就解决了问题。我没有立即注意到任何变化,但当我打开一个新的终端时,我发现我的主机名确实已经改变了。 - TSJNachos117sudo service hostname restart
命令失败了,显示错误信息为Failed to restart hostname.service: Unit hostname.service is masked.
- Ciro Santilli OurBigBook.com/etc/hosts
文件中没有包含机器名称,会发生什么情况? - 2540625/etc/hosts
文件中写什么?为什么没有人明确地说这个? - Dimshosts
中不存在现有计算机名称的实例。 - Dimssudo service hostname start
和 sudo hostname
时出现 "无法解析主机" 的错误。我正在使用 Ubuntu 16.04 LTS。 - Fabián/etc/hosts
已经被修改。 - E235hostnamectl set-hostname
在13.10+桌面上
如果您使用的是systemd(从13.10开始),并且cloud-init未激活(请参见下文),这是最佳方法:
hostnamectl set-hostname 'new-hostname'
它:
更多信息请参考:https://askubuntu.com/a/516898/52975
18.04及以后版本:cloud-init
18.04引入了cloud-init,可以控制主机名的设置,因此如果安装了cloud-init,则hostnamectl
更改在重启后将不会保留。待办事项:如何检查是否已安装,它是否默认安装在桌面镜像上还是只有服务器上?
如果您希望hostnamectl
的更改在重启后保留,那么您需要编辑cloud-init配置文件,禁用cloud-init的主机名设置/更新模块:
sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/' /etc/cloud/cloud.cfg
sudo touch /etc/cloud/cloud-init.disabled
/etc/hosts
文件,发现它还是旧的主机名。我将 /etc/hosts
中的主机名改为当前的主机名后,一切都正常工作了。 - E235sudo hostnamectl set-hostname myNewName
命令。在新终端和重启后,myNewName
将成为主机名,没有任何问题。 - Peter Krauss很简单:
编辑 /etc/hostname
,进行名称更改,保存文件。
还应该在 /etc/hosts
文件中进行相同的更改。
运行 sudo service hostname start
。
只要您没有依赖于“旧”主机名的应用程序设置,就应该没问题;-)
/etc/hosts
文件中没有任何关于我的主机名(新的或旧的)的参考,只有本地主机和一些IPv6规则。 - Olisudo service hostname restart
。 - Andrei Vajnahostname
现在是由upstart
管理的一个服务。它会执行完全相同的操作,重新启动该服务。 - Pavlos G.hostname
不再位于init.d
中。 - Rápli Andrássudo: /etc/init.d/hostname: command not found
- chovy无法启动hostname.service: Unit hostname.service已被屏蔽。
- Chloesudo -s
editor /etc/hostname
editor /etc/hosts
shutdown -ry now
sudo service hostname restart
来避免关闭。 - Wtowersudo editor /etc/postfix/main.cf
sudo service postfix restart
安装ailurus
添加PPA并更新您的软件源
sudo add-apt-repository ppa:ailurus && sudo apt-get update
安装ailurus
sudo apt-get install ailurus
安装完成后,可以在应用程序>>系统工具>>Ailurus中找到它
export PS1='\u@\h \w> '
hostname
命令来更改您的主机名。sudo hostname newname
gksudo /etc/hosts
127.0.0.1 oldname newname
sudo add-apt-repository ppa:tualatrix/ppa
然后执行 sudo apt-get update
和 sudo apt-get install ubuntu-tweak
。 - lofidevops/etc/hostname
文件:echo 'new_hostname' > /proc/sys/kernel/hostname
hostnamectl set-hostname "new_name"