实验环境
DHCP服务器、DNS服务器、HTTP服务器:虚拟机cnetos7
DHCP中继服务器:ensp三层交换机
DHCP客户端:虚拟机win10,ensp pc机
拓扑
要求
三层交换机做中继服务器
pc2自动获取地址
win10的IP和DNS自动获取,可解析www.hello.com(http服务器配置)
1、下载安装服务
yum -y install httpd //下载安装http服务
yum -y install dhcp //下载安装dhcp服务
yum -y install bind //下载安装dns服务
2、修改配置文件
2.1 修改http配置文件
[root@localhost ~]# vi /var/www/html/index.html //修改http主页文件
hello world //简单一点,只为验证能否解析
2.2 修改dhcp配置文件
[root@localhost ~]# vi /etc/dhcp/dhcpd.conf //修改dhcp的主配置文件
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "tvxq";
option domain-name-servers 192.168.30.3;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.30.0 netmask 255.255.255.0 { //必须创一个和网卡同网段的地址池
range 192.168.30.10 192.168.30.20; //地址段
}
subnet 192.168.10.0 netmask 255.255.255.0 { //创建一个vlan10的地址池
range 192.168.10.10 192.168.10.20; //地址段
option routers 192.168.10.1; //网关
}
subnet 192.168.20.0 netmask 255.255.255.0 { //创建一个vlan20的地址池
range 192.168.20.10 192.168.20.20; //地址段
option routers 192.168.20.1; //网关
option domain-name-servers 192.168.30.3; //dns
2.3 修改dns配置文件
2.3.1 修改dns主配置文件
[root@localhost ~]# vi /etc/named.conf //dns主配置文件
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
/*
2.3.2 修改区域配置文件
[root@localhost ~]# vi /etc/named.rfc1912.zones
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
...
zone "hello.com" IN { //定义正向DNS区域
type master; //定义区域类型
file "hello.com.zone"; //设置对应的正向区域地址数据库文件
allow-update { none; }; //设置允许动态更新的客户端地址(none为禁止)
};
2.3.3 创建正向域名解析数据库文件
[root@localhost named]# cp -p /var/named/named.localhost /var/named/hello.com.zone //连模板的属性一起复制
[root@localhost named]# vi /var/named/hello.com.zone //配置文件
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www A 192.168.30.3 //添加一条主机记录
2.4 配置ensp三层交换机
interface Vlanif10
ip address 192.168.10.1 255.255.255.0
dhcp select relay //开启dhcp中继
dhcp relay server-ip 192.168.30.3 //指定代理服务器的地址
#
interface Vlanif20
ip address 192.168.20.1 255.255.255.0
dhcp select relay
dhcp relay server-ip 192.168.30.3
#
interface Vlanif30
ip address 192.168.30.1 255.255.255.0
#
interface MEth0/0/1
#
interface GigabitEthernet0/0/1
port link-type trunk //设为trunk模式
port trunk allow-pass vlan 2 to 4094
2.5 配置二层交换机
interface Ethernet0/0/1
port link-type access //设为access模式
port default vlan 10 //加入vlan10
#
interface Ethernet0/0/2
port link-type access
port default vlan 20
#
interface Ethernet0/0/3
port link-type access
port default vlan 30
#
interface Ethernet0/0/4
port link-type trunk
port trunk allow-pass vlan 2 to 4094
3、启动服务并验证是否启动
[root@localhost named]# systemctl start httpd //开启http服务
[root@localhost named]# netstat -antp | grep 80 //监听80端口
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1807/dnsmasq
tcp6 0 0 :::80 :::* LISTEN 7823/httpd
[root@localhost named]#
[root@localhost named]# systemctl start named //开启dns服务
[root@localhost named]# netstat -antp | grep 53 //监听53端口
tcp 0 0 192.168.30.3:53 0.0.0.0:* LISTEN 7977/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 7977/named
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1807/dnsmasq
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 7977/named
tcp6 0 0 ::1:53 :::* LISTEN 7977/named
tcp6 0 0 ::1:953 :::* LISTEN 7977/named
[root@localhost named]#
[root@localhost named]# systemctl start dhcpd //开启dhcp服务
[root@localhost named]# netstat -anup | grep 67 //监听67端口
udp 0 0 0.0.0.0:67 0.0.0.0:* 7777/dhcpd
udp 0 0 0.0.0.0:67 0.0.0.0:* 1807/dnsmasq
[root@localhost named]#
4、验证结果
虚拟机win10
ensp pc2