From 2a23f5a573eabd08a67956661a4a4028cd92d692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=99=E7=82=9C=E5=BB=B7?= <1160093753@qq.com> Date: Sat, 26 Apr 2025 20:19:26 +0800 Subject: [PATCH] 35 --- ...55\347\273\247\351\205\215\347\275\256.md" | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 "40\351\230\231\347\202\234\345\273\267/20250426\350\267\257\347\224\261\345\231\250DHCP\346\234\215\345\212\241\345\231\250\345\217\212\344\270\255\347\273\247\351\205\215\347\275\256.md" diff --git "a/40\351\230\231\347\202\234\345\273\267/20250426\350\267\257\347\224\261\345\231\250DHCP\346\234\215\345\212\241\345\231\250\345\217\212\344\270\255\347\273\247\351\205\215\347\275\256.md" "b/40\351\230\231\347\202\234\345\273\267/20250426\350\267\257\347\224\261\345\231\250DHCP\346\234\215\345\212\241\345\231\250\345\217\212\344\270\255\347\273\247\351\205\215\347\275\256.md" new file mode 100644 index 0000000..5b19f2c --- /dev/null +++ "b/40\351\230\231\347\202\234\345\273\267/20250426\350\267\257\347\224\261\345\231\250DHCP\346\234\215\345\212\241\345\231\250\345\217\212\344\270\255\347\273\247\351\205\215\347\275\256.md" @@ -0,0 +1,126 @@ +# 路由器DHCP服务器及中继配置 + +### DHCP基础概念 + +**1.DHCP的作用** + +- **自动分配IP**:避免手动配置的麻烦和冲突 +- **集中管理**:统一分配IP、子网掩码、网关、DNS等 +- **提高效率**:动态回收和重用IP,适用于移动设备多的环境 + +**2.DHCP工作流程(DORA)** + ++ **Discover**:客户端广播寻找DHCP服务器 + ++ **Offer**:服务器回应可用的IP地址 + ++ **Request**:客户端确认使用该IP + ++ **Acknowledge**:服务器最终确认,分配IP + +**3.DHCP租约概念** + +- **租期**:IP地址的可用时间(如24小时) +- **T1(50%租期)**:客户端尝试续租原IP +- **T2(87.5%租期)**:若续租失败,广播请求新IP +- **到期未续租**:IP被回收,客户端需重新获取 + + + +### 核心代码 + +``` +基本配置步骤: +! 进入全局配置模式 +Router> enable +Router# configure terminal + +! 创建DHCP地址池 +Router(config)# ip dhcp pool LAN_POOL + +! 配置网络地址和子网掩码 +Router(dhcp-config)# network 192.168.1.0 255.255.255.0 + +! 配置默认网关 +Router(dhcp-config)# default-router 192.168.1.1 + +! 配置DNS服务器 +Router(dhcp-config)# dns-server 8.8.8.8 + +! 配置租约时间(可选,默认为1天) +Router(dhcp-config)# lease 7 [非所有版本的模拟器支持] + +! 退出DHCP配置模式 +Router(dhcp-config)# exit + +! 排除不分配的IP地址范围 ,比如网关 +Router(config)# ip dhcp excluded-address 192.168.1.100 192.168.1.254 + + + +验证命令: +! 查看DHCP地址池配置 +Router# show ip dhcp pool + +! 查看DHCP绑定信息 +Router# show ip dhcp binding + +! 查看DHCP冲突记录 +Router# show ip dhcp conflict! 查看DHCP地址池配置 +Router# show ip dhcp pool + +! 查看DHCP绑定信息 +Router# show ip dhcp binding + +! 查看DHCP冲突记录 +Router# show ip dhcp conflict + + + +排错命令: +! 清除DHCP绑定(谨慎使用) +Router# clear ip dhcp binding * + +``` + + + +### 使用DHCP服务器 + +![upgit_20250424_1745424927](https://gitee.com/que-weiting/picture/raw/master/img/upgit_20250426_1745669814.png) + +通过路由的DHCP中继模式,可以跨网连接DHCP服务器,为不同的局域网提供自动分配 + +``` +# 配置DHCP中继(当DHCP服务器不在本地网络时) +Router(config)# interface gigabitethernet0/0 +Router(config-if)# ip helper-address 10.1.1.1 + +在 Cisco 路由器上配置中继: +interface GigabitEthernet0/1 ! 连接 192.168.10.0/24 + ip address 192.168.10.254 255.255.255.0 + ip helper-address 172.16.100.100 ! 指向 DHCP 服务器 + no shutdown +! +interface GigabitEthernet0/2 ! 连接 192.168.20.0/24 + ip address 192.168.20.254 255.255.255.0 + ip helper-address 172.16.100.100 ! 指向 DHCP 服务器 + no shutdown +! +interface GigabitEthernet0/0 ! 连接 172.16.100.0/24(DHCP 服务器所在网络) + ip address 172.16.100.254 255.255.255.0 + no shutdown +``` + +#### **在 DHCP 服务器上创建两个作用域** + +- 作用域 1: + - 名称:`Subnet-192.168.10.0` + - IP 范围:`192.168.10.10 - 192.168.10.200` + - 子网掩码:`255.255.255.0` + - 网关:`192.168.10.254`(指向路由器接口) +- 作用域 2: + - 名称:`Subnet-192.168.20.0` + - IP 范围:`192.168.20.10 - 192.168.20.200` + - 子网掩码:`255.255.255.0` + - 网关:`192.168.20.254`(指向路由器接口) \ No newline at end of file -- Gitee