1.直接分配
设置地址池的名字 配置网段网关 dns 排除地址 租期等
显示配置
R1#show run
Building configuration...
Current configuration : 628 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname R1
!
ip dhcp excluded-address 192.168.1.1 排除地址
!
ip dhcp pool ccna
network 192.168.1.0 255.255.255.0 //网段
default-router 192.168.1.1 网关
option 150 ip 192.168.1.1 FTP服务器
dns-server 192.168.1.1 域名服务器
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
!
ip classless
line con 0
line vty 0 4
login
!
!
!
end
2.2.间接性的分配
在一个路由器上直接配置另外一个需分配的dhcp
方式与直接分配一致
注意的是,被需要分配的路由器端口填写的
ip helper-address 1.1.1.1(分配dhcp的地址进口)
显示配置
R1的配置
R1#show run
Building configuration...
Current configuration : 874 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname R1
!
!
ip dhcp excluded-address 192.168.10.1
ip dhcp excluded-address 192.168.20.1
!
ip dhcp pool ccna
network 192.168.10.0 255.255.255.0
default-router 192.168.10.1
option 150 ip 192.168.10.1
ip dhcp pool ccnp
network 192.168.20.0 255.255.255.0
default-router 192.168.20.1
option 150 ip 192.168.20.1
dns-server 192.168.20.1
!
interface FastEthernet0/0
ip address 1.1.1.1 255.255.255.252
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.10.1 255.255.255.0
duplex auto
speed auto
!
!
router rip
version 2
network 1.0.0.0
network 192.168.10.0
no auto-summary
!
ip classless
!
!
line con 0
line vty 0 4
login
!
!
end
R2的配置
R2#show run
Building configuration...
Current configuration : 576 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname R2
!
!
interface FastEthernet0/0
ip address 1.1.1.2 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.20.1 255.255.255.0
ip helper-address 1.1.1.1
duplex auto
speed auto
!
interface Vlan1
no ip address
shutdown
!
router rip
version 2
network 1.0.0.0
network 192.168.20.0
no auto-summary
!
ip classless
!
!
!
line con 0
line vty 0 4
login
3.3.通过dhcp服务器来分配
保证网络的联通
在dhcp上配置dhcp
在路由器上进入端口输入
ip helper-address 192.168.20.1
(分配dhcp端口的网段端口)
显示配置
server的配置
R1的配置
R1#show run
Building configuration...
Current configuration : 592 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname R1
!
!
!
interface FastEthernet0/0
ip address 192.168.10.1 255.255.255.0
ip helper-address 192.168.20.1 //server的ip地址
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.20.254 255.255.255.0
duplex auto
speed auto
!
ip classless
ip route 0.0.0.0 0.0.0.0 FastEthernet0/0
ip route 0.0.0.0 0.0.0.0 FastEthernet0/1
!
!
line con 0
line vty 0 4
login
!
!
!
end
测试结果
4.通过单臂路由来实现dhcp分配
在交换机上划分vlan
保证出口端口是switchport mode trunk模式
配置单臂路由
在dhcp服务器上配置vlan dhcp地址池
进入单臂路由子端口配置ip helper-address 192.168.30.1
显示配置
server配置
R1的配置
R1#show run
Building configuration...
Current configuration : 882 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname R1
!
!
interface FastEthernet0/0
no ip address
duplex auto
speed auto
!
interface FastEthernet0/0.10
encapsulation dot1Q 10
ip address 192.168.10.254 255.255.255.0
ip helper-address 192.168.30.1
!
interface FastEthernet0/0.20
encapsulation dot1Q 20
ip address 192.168.20.254 255.255.255.0
ip helper-address 192.168.30.1
!
interface FastEthernet0/1
ip address 192.168.30.254 255.255.255.0
duplex auto
speed auto
!
!
ip classless
ip route 0.0.0.0 0.0.0.0 FastEthernet0/1
ip route 0.0.0.0 0.0.0.0 FastEthernet0/0.10
ip route 0.0.0.0 0.0.0.0 FastEthernet0/0.20
ip route 0.0.0.0 0.0.0.0 FastEthernet0/0
!
!
!
line con 0
line vty 0 4
login
!
end
测试结果
5.DHCP 命令汇总
命令 作用
show ip dhcp pool 查看DHCP 地址池的信息
show ip dhcp binding 查看DHCP 的地址绑定情况
show ip dhcp database 查看DHCP 数据库
show ip interface 查看接口信息
debug ip dhcp server events 动态查看DHCP 服务器的事件
service dhcp 开启DHCP 服务
no ip dhcp conflict logging 关闭DHCP 冲突日志
ip dhcp pool 配置DHCP 分配的地址池
network DHCP 服务器要分配的网络和掩码
default-router 默认网关
domain-name 域名
netbios-name-server WINS 服务器
dns-server 域名服务器
option 150 ip FTP 服务器
lease 配置租期
ip dhcp excluded-address 排除地址段
ip helper-address 配置DHCP 中继的地址
6.总结,
在分配dhcp时,有时候是不需要配置默认路由,但是为了更好实施,最好可以配置一下,不同的分配方式会带来不同的负载和流量,可以根据路由器型号的好坏。转发能力来决定哪一种更好!希望大家多多指教!