动态主机配置协议
动态主机配置协议DHCP
作用:
在企业网络中通过使用动态主机配置协议DHCP,来为大量主机分配IP地址等网络参数可以减少管理员工作量,避免出错
DHCP角色:
- DHCP服务器
- DHCP客户端
- DHCP中继
DHCP服务器 - windows server 2012
- centos7
- 路由器,三层交换
- 无线路由器
路由DHCP的三种模式:
- 全局模式
- 接口模式
- 中继代理模式
1.DHCP工作原理
discover 发现 寻找DHCP服务器 广播
offer 回应 我是DHCP服务器 单播
request 请求 请给我一个IP地址 广播
ack 确认 给你IP 单播
2.租约更新
自动更新租约 50% 87.5%
手动更新租约 ipconfig /renew
3.租约释放
自动释放 客户机关机,网络中继,租约到期
手动释放 ipconfig /release
DHCP全局模式:永久
配置基于全局模式的DHCP服务器
[dhcp]dhcp enable //启用DHCP功能
[dhcp]ip pool xixi //创建地址池
[dhcp-ip-pool-xixi]network 192.168.1.0 mask 24 //指明网段和掩码
[dhcp-ip-pool-xixi]gateway-list 192.168.1.1 //指明网关
[dhcp-ip-pool-xixi]dns-list 202.106.0.20 //指明dns服务器地址
[dhcp-ip-pool-xixi]lease day 0 hour 1 minute 30 //指明租约
[dhcp-ip-pool-xixi]excluded-ip-address 192.168.1.200 192.168.1.254
//指明排除的地址范围
[dhcp]int g0/0/0
[dhcp-GigabitEthernet0/0/0]ip address 192.168.1.1 24
[dhcp-GigabitEthernet0/0/0]dhcp select global //启用DHCP全局模式
3.为接口启用DHCP功能
int g0/0/3
dhcp select global //接口下启用DHCP功能
DHCP接口模式:临时
配置基于接口模式的DHCP服务器
[r1]dhcp enable //启用DHCP功能
[r1]int g0/0/1
[r1-G0/0/1]ip address 192.168.2.1 24
[r1-G0/0/1]dhcp select interface //启用DHCP接口模式
此处隐含了DHCP网段和网关的设置,网段为接口IP所在网段,网关为接口IP,不可改变
[r1-G0/0/1]dhcp server dns-list 2.2.2.2
[r1-G0/0/1]dhcp server lease day 2
[r1-G0/0/1]dhcp server excluded-ip-address 192.168.2.200 192.168.2.254
如果重新配置了接口的IP地址,DHCP的所有配置就都不存在了
DHCP中继代理
配置中继代理服务器
在没有DHCP服务器的网段,需要配置DHCP中继代理服务器
[relay]dhcp enable
[relay]int g0/0/0 //进入跟客户端相连接口
[relay-G0/0/0]dhcp select relay //启用中继代理模式
[relay-G0/0/0]dhcp relay server-ip 192.168.2.1 //指明DHCP服务器地址
在三层交换机上配置DHCP服务
问题
配置两个地址池:192.168.1.0/24和192.168.2.0/24
配置两个VLAN:VLAN 10和VLAN 20
将四台主机分别加入VLAN
自动获取IP地址,确保全网互通
配置思路:
LSW1
1.创建VLAN
vlan batch 10 20
2.更改端口类型,并将端口加入VLAN
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 2 to 4094
3.全局开启DHCP 服务
dhcp enable
4.创建地址池
ip pool 1
gateway-list 192.168.1.254
network 192.168.1.0 mask 255.255.255.0
lease day 7 hour 0 minute 0
dns-list 8.8.8.8
#
ip pool 2
gateway-list 192.168.2.254
network 192.168.2.0 mask 255.255.255.0
lease day 7 hour 0 minute 0
dns-list 8.8.8.8
5.配置网关地址,并在接口下启用DHCP功能
interface Vlanif10
ip address 192.168.1.254 255.255.255.0
dhcp select global
#
interface Vlanif20
ip address 192.168.2.254 255.255.255.0
dhcp select global
LSW2:
1.创建VLAN
vlan batch 10 20
2.更改接口类型,并将接口加入VLAN
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
#
interface Ethernet0/0/2
port link-type access
port default vlan 10
#
interface Ethernet0/0/3
port link-type access
port default vlan 10
LSW3:
1.创建VLAN
vlan batch 10 20
2.更改接口类型,并将接口加入VLAN
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
#
interface Ethernet0/0/2
port link-type access
port default vlan 20
#
interface Ethernet0/0/3
port link-type access
port default vlan 20
测试:
pc1 ping pc3 pc4
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe29:1273
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.1.253
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.1.254
Physical address..................: 54-89-98-29-12-73
DNS server........................: 8.8.8.8
```bash
PC>ping 192.168.2.250
Ping 192.168.2.250: 32 data bytes, Press Ctrl_C to break
From 192.168.2.250: bytes=32 seq=1 ttl=127 time=94 ms
From 192.168.2.250: bytes=32 seq=2 ttl=127 time=62 ms
From 192.168.2.250: bytes=32 seq=3 ttl=127 time=94 ms
From 192.168.2.250: bytes=32 seq=4 ttl=127 time=93 ms
From 192.168.2.250: bytes=32 seq=5 ttl=127 time=63 ms
--- 192.168.2.250 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/81/94 ms
PC>ping 192.168.2.253
Ping 192.168.2.253: 32 data bytes, Press Ctrl_C to break
From 192.168.2.253: bytes=32 seq=1 ttl=127 time=78 ms
From 192.168.2.253: bytes=32 seq=2 ttl=127 time=94 ms
From 192.168.2.253: bytes=32 seq=3 ttl=127 time=94 ms
From 192.168.2.253: bytes=32 seq=4 ttl=127 time=78 ms
From 192.168.2.253: bytes=32 seq=5 ttl=127 time=94 ms
--- 192.168.2.253 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 78/87/94 ms
pc2 ping pc3 pc4
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:feba:13e4
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.1.250
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.1.254
Physical address..................: 54-89-98-BA-13-E4
DNS server........................: 8.8.8.8
PC>ping 192.168.2.253
Ping 192.168.2.253: 32 data bytes, Press Ctrl_C to break
From 192.168.2.253: bytes=32 seq=1 ttl=127 time=94 ms
From 192.168.2.253: bytes=32 seq=2 ttl=127 time=109 ms
From 192.168.2.253: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.2.253: bytes=32 seq=4 ttl=127 time=94 ms
From 192.168.2.253: bytes=32 seq=5 ttl=127 time=94 ms
--- 192.168.2.253 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 78/93/109 ms
PC>ping 192.168.2.250
Ping 192.168.2.250: 32 data bytes, Press Ctrl_C to break
From 192.168.2.250: bytes=32 seq=1 ttl=127 time=62 ms
From 192.168.2.250: bytes=32 seq=2 ttl=127 time=62 ms
From 192.168.2.250: bytes=32 seq=3 ttl=127 time=78 ms
From 192.168.2.250: bytes=32 seq=4 ttl=127 time=94 ms
From 192.168.2.250: bytes=32 seq=5 ttl=127 time=78 ms
--- 192.168.2.250 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/74/94 ms
上一篇: Oracle查询当前的crs/has自启动状态实例教程
下一篇: 解决某个端口被占用的问题
推荐阅读
-
[build.gradle配置系列(一)]android studio根据版本号动态生成apk名
-
ansible动态Inventory主机清单配置遇到的坑
-
Apache虚拟主机的配置和泛域名解析实现代码
-
如何配置apache虚拟主机的实例小结
-
CentOS 6.1 环境中部署nginx、php(包括fastcgi)、虚拟主机配置
-
C#编程实现动态改变配置文件信息的方法
-
tomcat配置ssl证书ip访问(tomcat配置https协议)
-
Spring Cloud动态配置实现原理与源码分析
-
linux修改hostname的配置文件(linux中修改主机名的命令)
-
本地机apache配置基于域名的虚拟主机详解