• ubuntu永久修改主机名


    http://blog.csdn.net/ruglcc/article/details/7802077

    1、查看主机名


    在Ubuntu系统中,快速查看主机名有多种方法:
    其一,打开一个GNOME终端窗口,在命令提示符中可以看到主机名,主机名通常位于“@”符号后;
    其二,在终端窗口中输入命令:hostname或uname –n,均可以查看到当前主机的主机名。

    2、临时修改主机名

    命令行下运行命令:“hostname 新主机名”
    其中“新主机名”可以用任何合法字符串来表示。不过采用这种方式,新主机名并不保存在系统中,重启系统后主机名将恢复为原先的主机名称。
    例子:hostname ubuntu-temp
    这样主机名字就临时被修改为ubuntu-temp,但是终端下不会立即显示生效后的主机名,重开一个终端窗口(通过ssh连接的终端需要重新连接才可以);


    3、永久修改主机名

    在Ubuntu系统中永久修改主机名也比较简单。主机名存放在/etc/hostname文件中,修改主机名时,编辑hostname文件,在文件中输入新的主机名并保存该文件即可。重启系统后,参照上面介绍的快速查看主机名的办法来确认主机名有没有修改成功。

    值的指出的是,在其它Linux发行版中,并非都存在/etc/hostname文件。如Fedora发行版将主机名存放在/etc/sysconfig/network文件中。所以,修改主机名时应注意区分是哪种Linux发行版。

    3、/etc/hostname与/etc/hosts的区别
    /etc/hostname中存放的是主机名,hostname文件的一个例子:
    v-jiwan-ubuntu-temp

    /etc/hosts存放的是域名与ip的对应关系,域名与主机名没有任何关系,你可以为任何一个IP指定任意一个名字,hostname文件的一个例子:
    127.0.0.1       localhost
    127.0.1.1       v-jiwan-ubuntu

    1.症状:

    当你是使用sudo来执行命令时,总是在命令执行时,首先输出:“sudo:unable to resolve host Lily-desktop”(假设Lily-desktop 是你的当前主机的名字(host-name)), 但是怎样才能使使用sudo像以前一样不错误提示,正常工作呢。

    when you’re running commands with sudo at beginning.It outputs “sudo:unable to resolve host Lily-desktop”(here assume current host-name is Lily-desktop),however the commands work as well as before.

    2.产生该症状的原因:

    这种症状经常发生在更改了hostname的情形下。在通过 编辑  /etc/hostname 改变了主机名字(hostname)之后, 我们还需要改变 /etc/hosts文件的相应部分的内容

    This always happens after host-name changed.After change host-name by edit /etc/hostname,we also need to do a change in /etc/hosts file.

    3.解决方案:

    Solve:
    Edit /etc/hosts:   // 编辑  /etc/hosts 文件

    gksudo gedit /etc/hosts

    make it looks like (change boldfaced words to current host-name): //使粗体字对应的词与当前的主机名即hostname 一致

    127.0.0.1	localhost
    
    127.0.1.1	Lily-desktop
    
    
    
    
    # The following lines are desirable for IPv6 capable hosts
    
    ::1     localhost ip6-localhost ip6-loopback
    
    fe00::0 ip6-localnet
    
    ff00::0 ip6-mcastprefix
    
    ff02::1 ip6-allnodes
    
    ff02::2 ip6-allrouters
    
    ff02::3 ip6-allhosts
  • 相关阅读:
    Objective-C 排序
    Objective-C 工厂方法
    Objective-C 关键字:retain, assgin, copy, readonly,atomic,nonatomic
    iOS UINavigationController的使用
    iOS UITabBarController的使用
    iOS UISearchController的使用
    iOS中延时执行的几种方式的比较和汇总
    iOS适配 旧项目工程在iOS9下不能正常显示
    iOS Block界面反向传值
    iOS Block简介
  • 原文地址:https://www.cnblogs.com/cnland/p/3070426.html
Copyright © 2020-2023  润新知