dns用于域名解析,既是一个服务又是一个协议,DNS使用UDP端口53
主机名+域名成为完全合格域名(FQDN)
最上面是根域:“.”
然后是顶级域:.com,.cn.net等等
下面是二级域:.com.cn,.edu.cn等等
再下面是三级域或子域:.sina.com.cn,.yahoo.com.cn等等
最前面是主机名:www,mail等等
当客户机访问一个域名时,dns服务器会有两种查询方式,递归查询和迭代查询
递归查询:直接能查到想去的域名
迭代查询:直接查不到,需要多次查找想去的域名
dns的安装包是bind
直接用yum安装bind包
搭建dns服务器需要修改三个配置文件
第一个是/etc/named.conf主配置文件
options { listen-on port 53 { any; }; // 改为any listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; // 改为any
第二个配置文件是/etc/named.rfc1912.zones 区域配置文件
zone "test.com" IN { // 设置一个域名 type master; file "test.com.zone"; // 创建一个同名的文件 allow-update { none; }; };
第三个配置文件就是创建一个第二步的同名文件在/var/named/下面
[root@localhost named]# pwd /var/named [root@localhost named]# ls data dynamic named.ca named.empty named.localhost named.loopback slaves test.com.zone
然后在里面添加一条
这时候在客户机上解析域名
首先配置三层交换机上的配置
interface Vlanif10 ip address 192.168.10.1 255.255.255.0 dhcp select relay //设置dhcp中继 dhcp relay server-ip 192.168.3.1 //指定dhcp服务器 # interface Vlanif20 ip address 192.168.20.1 255.255.255.0 dhcp select relay dhcp relay server-ip 192.168.3.1 # interface Vlanif30 ip address 192.168.3.2 255.255.255.0 dhcp select relay dhcp relay server-ip 192.168.3.1 # interface GigabitEthernet0/0/1 port link-type trunk port trunk allow-pass vlan 2 to 4094 #
设置云端客户机仅主机模式
设置云端服务器为net模式
在服务器上先配置httpd服务,安装httpd
[root@localhost conf]# rpm -q httpd httpd-2.4.6-97.el7.centos.x86_64 [root@localhost conf]# netstat -antp | grep httpd tcp6 0 0 :::80 :::* LISTEN 25230/httpd
创建一个httpd的首页
进入/var/www/html/下创建一个index.html,然后写内容
[root@localhost conf]# vim /var/www/html/index.html hello world ~ ~ ~ ~
然后再配置dhcp服务,先安装dhcp,然后写下三个地址池,并指定10网段的dns
[root@localhost conf]# rpm -q dhcp dhcp-4.2.5-82.el7.centos.x86_64 [root@localhost conf]# vim /etc/dhcp/dhcpd.conf subnet 192.168.3.0 netmask 255.255.255.0 { range 192.168.3.10 192.168.3.20; option routers 192.168.3.2; } subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.10 192.168.10.20; option routers 192.168.10.1; option domain-name-servers 192.168.3.1; } subnet 192.168.20.0 netmask 255.255.255.0 { range 192.168.20.10 192.168.20.20; option routers 192.168.20.1; }
此时20网段的客户机可以自动获取ip了
此时再配置dns服务,先安装dns服务,注意安装包是bind而不是dns
[root@localhost conf]# rpm -q bind bind-9.11.4-26.P2.el7_9.5.x86_64
先配置主配置文件
[root@localhost conf]# rpm -qc bind /etc/logrotate.d/named /etc/named.conf /etc/named.iscdlv.key /etc/named.rfc1912.zones /etc/named.root.key /etc/rndc.conf /etc/rndc.key /etc/sysconfig/named /var/named/named.ca /var/named/named.empty /var/named/named.localhost /var/named/named.loopback [root@localhost conf]# vim /etc/named.conf options { listen-on port 53 { any; }; //设为any listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; //设为any
然后配置区域配置文件
[root@localhost conf]# vim /etc/named.rfc1912.zones zone "test.com" IN { //取一个域名 type master; file "test.com.zone"; //指定数据文件 allow-update { none; }; };
然后配置区域数据文件,先将模板拷贝过来,然后再编辑
[root@localhost conf]# cd /var/named/ [root@localhost named]# cp -p named.localhost test.com.zone [root@localhost named]# vim /var/named/test.com.zone $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1 AAAA ::1 www IN A 192.168.3.1 //添加一条
此时win10就可以获取到ip并解析dns了
然后用域名访问网页