1、建立DNS服务器,同时为magedu.com, test.net, example.org三个域提供解析;要求,每个域内的www主机均指向本机唯一的IP;(IP:172.16.2.1)

2、建立httpd服务器,分别为www.magedu.com, www.test.net, www.example.org各提供一个虚拟主机,位置分别为:/vhosts/magedu, /vhosts/test, /vhosts/example;要求:

 1)每个虚拟主机的要使用各自的错误日志和访问日志;三个虚拟主机的日志文件都位于/vhosts/logs目录中;

  2)www.magedu.com虚拟主机仅允许来自172.16.0.0/16(除了172.16.100.0/24)的主机访问;

 3)www.test.org虚拟主机仅允许提供了帐号和密码的请求者访问;

4)通过http://www.example.org/mail可以访问/web/mail目录中的网页;

 

测试主机的 dns指向刚才配置的dns服务器的地址 172.16.2.1 

测试web 服务  

 

一 、配置dns 

  1、安装

  1. #yum -y install bind97 bind97-devel bind97-libs bind97-utils 

   2、配置主配置文件

 

  1.  #vim /etc/named.conf 
  2.  options { 
  3.         directory       "/var/named"; 
  4. }; 
  5. zone "." IN { 
  6.         type hint; 
  7.         file "named.ca"; 
  8. }; 
  9. zone "localhost.localdomain" IN { 
  10.           type master; 
  11.           file "named.localhost"; 
  12.           allow-update { none; }; 
  13.   }; 
  14. zone "localhost" IN { 
  15.           type master; 
  16.           file "named.localhost"; 
  17.           allow-update { none; }; 
  18.   }; 
  19. zone "test.net." IN { 
  20.           type master; 
  21.           file "test.net.zone"; 
  22.           allow-update { none; }; 
  23.   }; 
  24. zone "example.org" IN { 
  25.           type master; 
  26.           file "example.org.zone"; 
  27.           allow-update { none; }; 
  28.   }; 
  29. zone "magedu.com" IN {

              type master;

              file "magedu.com.zone";

              allow-update { none; };

      };    
  30.  

    3、配置区域文件

  1. # vim magedu.com.zone 
  2.      $TTL 600 
  3. @       IN SOA  ns.magedu.com. admin.magedu.com. ( 
  4.                                         0       ; serial 
  5.                                         1D      ; refresh 
  6.                                         1H      ; retry 
  7.                                         1W      ; expire 
  8.                                         3H )    ; minimum 
  9.         IN      NS      ns.magedu.com. 
  10. ns      IN      A       172.16.2.1 
  11. www     IN      A       172.16.2.1   

    另外两个和这个同样

 

  1. #cd /var/named/ 
  2. #ll 
  3. total 88 
  4. drwxr-x--- 4 root  named 4096 Jul  4 20:38 chroot 
  5. drwxrwx--- 2 named named 4096 Jul  4 20:53 data 
  6. drwxrwx--- 2 named named 4096 Jul  4 21:03 dynamic 
  7. -rw-r----- 1 root  named  208 Jul  4 21:37 example.org.zone   1 
  8. -rw-r----- 1 root  named  203 Jul  4 20:53 magedu.com.zone   2   
  9. -rw-r----- 1 root  named 1892 Jul  4 20:42 named.ca 
  10. -rw-r----- 1 root  named  152 Dec 15  2009 named.empty 
  11. -rw-r----- 1 root  named  152 Jul  4 20:44 named.localhost     
  12. -rw-r----- 1 root  named  168 Dec 15  2009 named.loopback 
  13. drwxrwx--- 2 named named 4096 Nov 17  2011 slaves 
  14. -rw-r----- 1 root  named  199 Jul  4 21:36 test.net.zone        3        
  15.  
  16. 三个配置文件 记得修改数组  为named   

   4、开机自动启动 

  1. # chkconfig --list named 
  2. named           0:off   1:off   2:off   3:off   4:off   5:off   6:off   
  3. #chkconfig  named on  在2345级别默认启动   
  4. # chkconfig --list named 
  5. named           0:off   1:off   2:on    3:on    4:on    5:on    6:off 

    5、启动服务 

  1. #service named start   
  2. # netstat -tnlp  查看端口  

     6、测试

  1. # vim /etc/resolv.conf 
  2. nameserver 172.16.2.1   dns 指向自己的IP   
  3. search localdomain      
  4.  
  5. dig  host  nslookup   三个命令都可以测试   
  6. # dig -t A www.magedu.com 
  7. <<>> DiG 9.7.0-P2-RedHat-9.7.0-6.P2.el5_7.4 <<>> -t A www.magedu.com 
  8. ;; global options: +cmd 
  9. ;; Got answer: 
  10. ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43869 
  11. ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 
  12. ;; QUESTION SECTION: 
  13. ;www.magedu.com.            IN  A 
  14.  
  15. ;; ANSWER SECTION: 
  16. www.magedu.com.     600 IN  A   172.16.2.1 
  17.  
  18. ;; AUTHORITY SECTION: 
  19. magedu.com.     600 IN  NS  ns.magedu.com. 
  20.  
  21. ;; ADDITIONAL SECTION: 
  22. ns.magedu.com.      600 IN  A   172.16.2.1 
  23.  
  24. ;; Query time: 32 msec 
  25. ;; SERVER: 172.16.2.1#53(172.16.2.1) 
  26. ;; WHEN: Wed Jul  4 22:02:46 2012 
  27. ;; MSG SIZE  rcvd: 81 
  28.  
  29. # host -t A www.magedu.com 
  30. www.magedu.com has address 172.16.2.1 
  31. #nslookup  是个交互式的命令   

 

dig  host  nslookup   三个命令都可以测试 有兴趣可以自己摸索

 

测试web时我们就可以把测试机的dns指向上面dns的IP  dns与web 结合 

 

二、配置web服务 

   1、安装 

 

       #yum -y install httpd 

 

   2、配置虚拟主机

  1. # vim /etc/httpd/conf/httpd.conf  
  2. NameVirtualHost *:80 
  3. <VirtualHost *:80> 
  4.     DocumentRoot /www/vhosts/magedu 
  5.     ServerName www.magedu.com 
  6.     ErrorLog /var/log/httpd/magedu.error_log    不同的访问日志   
  7.     CustomLog /var/log/httpd/magedu.access_log common 
  8. </VirtualHost> 
  9. <VirtualHost *:80> 
  10.     DocumentRoot /www/vhosts/test 
  11.     ServerName www.test.net 
  12.     ErrorLog /var/log/httpd/test.error_log 
  13.     CustomLog /var/log/httpd/test.access_log common 
  14. </VirtualHost> 
  15. <VirtualHost *:80> 
  16.     DocumentRoot /www/vhosts/example 
  17.     ServerName www.example.org 
  18.     ErrorLog /var/log/httpd/example.error_log 
  19.     CustomLog /var/log/httpd/example.access_log common 
  20. </VirtualHost> 

      3、修该,定义访问权限 

  1. <VirtualHost *:80> 
  2.     DocumentRoot /www/vhosts/magedu 
  3.     ServerName www.magedu.com 
  4.     ErrorLog /var/log/httpd/magedu.error_log 
  5.     CustomLog /var/log/httpd/magedu.access_log common 
  6.         <Directory "/www/vhosts/magedu"> 
  7.             Options none 
  8.             AllowOverride none 
  9.             Order deny,allow  
  10.             Deny from 192.168.0.142 
  11.         </Directory> 
  12. </VirtualHost> 

      4、修改,基于密码访问

  1. <VirtualHost *:80> 
  2.     DocumentRoot /www/vhosts/test 
  3.     ServerName www.test.net 
  4.     ErrorLog /var/log/httpd/test.error_log 
  5.     CustomLog /var/log/httpd/test.access_log common 
  6.         <Directory "/www/vhosts/test"> 
  7.             Options none 
  8.             AllowOverride AuthConfig     允许覆盖 以密码认证 
  9.             AuthType Basic         认证方式 (basic 认证和 摘要认证 MD5)  
  10.             AuthName "restricted area"   名字     
  11.             AuthUserFile "/etc/httpd/conf/.htpasswd"  存放位置   
  12.             Require valid-user       允许上个文件中的所有用户   
  13.         </Directory> 
  14. </VirtualHost> 

       5、创建密码文件 和允许访问的用户 

  1. # htpasswd -c -m /etc/httpd/conf/.htpasswd gentoo   创建密码 文件    gentoo 用户可以访问   
  2. New password:  
  3. Re-type new password:  
  4. Adding password for user gentoo 
  5. #htpasswd -b -m /etc/httpd/conf/.htpasswd ubuntu redhat  创建ubuntu 用户  密码 redhat  

   

练习 dns web _dns web

 

 

6、添加别名

  1. <VirtualHost *:80> 
  2.     DocumentRoot /www/vhosts/example 
  3.     ServerName www.example.org 
  4.     ErrorLog /var/log/httpd/example.error_log 
  5.     CustomLog /var/log/httpd/example.access_log common 
  6.     Alias   /mail/  "/web/mail/"     别名    
  7. </VirtualHost> 

 

练习 dns web _dns web  _02

dns 与web 结合 基本就如此 ,我们要学会使用,学是为了用,用时为了跟好的学