Ubuntu 12.04 LTS 修改主机名

总体来说就是修改 /etc/hostname /etc/hosts 即可


1. 安装完系统的初始情况

/etc/hostname

vm1-ubuntu-svr

/etc/hosts

127.0.0.1       localhost
127.0.1.1       vm1-ubuntu-svr.localdomain      vm1-ubuntu-svr

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


2. /etc/hostname

/etc/hostname This file should only contain the hostname and not the full FQDN.(man hostname)


FQDN

完整网域名称由主机名称与母网域名称两部份所组成,例如有一部服务器的本地主机名为myhost,而其母域名为example.com,那指向该服务器的完整网域名称就是myhost.example.com。虽然世界上可能有很多服务器的本地主机名是myhost,但myhost.example.com是唯一的,因此完整网域名称能识别该特定服务器。(完整网域名称


也就是说,对于 myhost.example.com, /etc/hostname 中只用填写 myhost.


3. /etc/hosts

这个文件是用来记录 IP 与主机映射关系的静态文件,和 Windows 的 C:\Windows\System32\drivers\etc\hosts 功能是一样的。

格式:

IP_address canonical_hostname [aliases...]

例子:

127.0.0.1       localhost
192.168.1.10    foo.mydomain.org       foo
192.168.1.13    bar.mydomain.org       bar
146.82.138.7    master.debian.org      master
209.237.226.90  www.opensource.org
(man hosts)

别名可有可无


4. 修改之后

/etc/hostname

controller.openstack

/etc/hosts

127.0.0.1       localhost
127.0.1.1       controller.openstack    controller

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


参考资料

man hostname

man hosts

Changing the hostname or computer name in ubuntu

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值