hosts 又称 host table,可译为“主机表”,是一个没有扩展名的操作系统文件,以表的形式存储了主机名和IP地址的映射关系。
1、操作 hosts 文件需要 root 权限,所以我们需要先切换到 root 用户。
su -
2、vim 编辑/etc/hosts
文件
vim /etc/hosts
3、输入你想要更改的内容,然后按:wq
保存退出即可。
127.0.0.1 test.com
127.0.0.1 test2.com
127.0.0.1 test3.com
规则:比如 127.0.0.1 test.com,那么你访问 test.com 的时候 其实访问的是127.0.0.1。
4、ping 测试,成功。
[root@fedora ~]# ping test01.com
PING test01.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.828 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.128 ms