1. 程式人生 > >配置IP和主機名對映

配置IP和主機名對映

1. 修改主機名字hostname

[[email protected]]$ sudo vi /etc/sysconfig/network

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for note1:#在這裡輸入密碼
#Created by anaconda
HOSTNAME=note(新增這一行)
#新增上面的這行文字然後按ctrl+c,輸入":wq"按enter建退出
~
~
~
"/etc/hosts" 5L, 221C written
[
[email protected]
]$su - root (獲取root許可權) Password: (輸入root的密碼) Last login: Wed Sep 26 07:14:35 ADT 2018 on pts/0 [[email protected]~]# hostname note(執行) [[email protected]~]# su - note1 Last login: Wed Sep 26 07:15:37 ADT 2018 on pts/0 [[email protected]~]$

2. 修改ip地址與主機名對映

[[email protected]
~]$ sudo vi /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.16.100 note1(新增這一行,當然你也可以新增多臺主機名的對映) ~ ~ "/etc/hosts" 3L, 179C written [[email protected] ~]$ ping note1(最後ping就能ping到了) PING note1 (192.168.16.100) 56(84) bytes of data. 64 bytes from note1 (192.168.16.100): icmp_seq=1 ttl=64 time=0.090 ms 64 bytes from note1 (192.168.16.100): icmp_seq=2 ttl=64 time=0.035 ms 64 bytes from note1 (192.168.16.100): icmp_seq=3 ttl=64 time=0.035 ms 64 bytes from note1 (192.168.16.100): icmp_seq=4 ttl=64 time=0.035 ms 64 bytes from note1 (192.168.16.100): icmp_seq=5 ttl=64 time=0.069 ms 64 bytes from note1 (192.168.16.100): icmp_seq=6 ttl=64 time=0.036 ms 64 bytes from note1 (192.168.16.100): icmp_seq=7 ttl=64 time=0.058 ms