一.DNS
dns: 负责作域名转换成ip这个工作的主机叫做dns服务器(地址解析)
1.DNS指向性文件
vim /etc/resolv.conf ##dns服务器指向文件临时
nameserver 114.114.114.114 ##114.114.114.114 为电信dns服务器
当我们去访问ping www.baidu.com ,去询问指向性文件 /etc/resolv.conf 里的114.114.114.114 www.baidu.com对应的ip是多少
www.baidu.com = 39.156.66.18
2.本地解析
vim /etc/hosts ##叫做本地解析文件
39.156.66.18 www.baidu.com
3.DNS永久设定
vim /etc/sysconfig/network-scripts/ifcfg-ens160 ##dns的永久设定
DNS1=114.114.114.114
注意:设置完成后重启网络服务
DNS实验
1.设定主机ip和windows在一个网段
2.设定主机网关和windows相同
[root@rhel7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
3.在windows中ping www.baidu.com 查看百度ip
4.在linux中可以ping通百度ip
[root@rhel7 ~]# ping 61.135.169.125
PING 61.135.169.125 (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125: icmp_seq=1 ttl=55 time=76.0 ms
64 bytes from 61.135.169.125: icmp_seq=2 ttl=55 time=16.0 ms
5.在linux中ping www.baidu.com 不可以
[root@rhel7 network-scripts]# ping www.baidu.com
ping: www.baidu.com: Name or service not known
6.编写本地解析文件/etc/hosts
61.135.169.125 www.baidu.com
ping www.baidu.com 可以
[root@rhel7 network-scripts]# ping www.baidu.com
PING www.baidu.com (61.135.169.121) 56(84) bytes of data.
64 bytes from www.baidu.com (61.135.169.121): icmp_seq=1 ttl=55 time=16.1 ms
64 bytes from www.baidu.com (61.135.169.121): icmp_seq=2 ttl=55 time=17.9 ms
ping www.qq.com 不可以
[root@rhel7 network-scripts]# ping www.qq.com
ping: www.qq.com: Name or service not known
7.指向性文件/etc/resolv.conf
nameserver 114.114.114.114
ping www.qq.com 可以
[root@rhel7 network-scripts]# ping www.qq.com
PING public-v6.sparta.mig.tencent-cloud.net (220.194.111.148) 56(84) bytes of data.
64 bytes from dns148.online.tj.cn (220.194.111.148): icmp_seq=1 ttl=55 time=23.8 ms
64 bytes from dns148.online.tj.cn (220.194.111.148): icmp_seq=2 ttl=55 time=21.1 ms