案例:DNS与Web
虚拟机A:构建DNS服务器 虚拟机B:构建web服务器
虚拟机B:构建服务器,实现基于域名的虚拟web主机
提供 www.sina.com www.nsd.com
[root@pc207 ~]# yum install -y httpd
[root@pc207 ~]# mkdir /var/www/sina
[root@pc207 ~]# mkdir /var/www/nsd
[root@pc207 ~]# echo '<h1>wo shi sina' >/var/www/sina/index.html
[root@pc207 ~]# echo '<h1>wo shi nsd' >/var/www/nsd/index.html
[root@pc207 ~]# vim /etc/httpd/conf.d/nsd.conf
<virtualhost *:80>
servername www.sina.com
documentroot /var/www/sina
</virtualhost>
<virtualhost *:80>
servername www.nsd.com
documentroot /var/www/nsd
</virtualhost>
[root@pc207 ~]# systemctl restart httpd
3.利用本机文件/etc/hosts进行解析验证
[root@pc207 ~]# vim /etc/hosts
# ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost localhost