十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
自动分配
创新互联专注于企业网络营销推广、网站重做改版、垣曲网站定制设计、自适应品牌网站建设、H5网站设计、商城网站建设、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为垣曲等各大城市提供网站开发制作服务。
手动分配
客户机从DHCP服务器获得IP地址的工程称为DHCP的租约过程
租约过程分为4个步骤
1、客户机请求IP地址 Discover
2、响应服务 Offer
3、客户机选择IP地址 Request
4、服务器确定租约 ACK
DHCP客户机每次重新登录网络时,不需要再发送DHCP Discover信息,而是直接发送包含前一次所分配的IP地址的DHCP Request请求信息
DHCP服务
为大量客户机自动分配地址,提供集中管理
减轻管理和维护成本、提高网络配置效率
可分配的地址信息主要包括
网卡的IP地址、子网掩码
对应的网络地址、广播地址
默认网关地址
DNS服务器地址
[root@localhost ~]# yum install dhcp -y
主配置文件
/etc/dhcp/dhcpd.conf
/var/lib/dhcpd/dhcpd.lease
修改网卡配置文件
BOOTPROTO=dhcp
dhclient
命令
dhclient [-d] [网络接口名]
使用VMware 15
下载链接 许可证密匙
:UY758-0RXEQ-M81WP-8ZM7Z-Y3HDA
c3725路由镜像文件
下载链接使用GNS3 1.3.1
下载链接 使用方法
win 10 镜像
下载链接win 7 镜像
下载链接CentOS 7镜像
下载链接1、在GNS3中搭建DHCP中继服务的拓扑图,方便我们搭建服务的时候理清思路。在这里我使用一台win 10虚拟机、一台win 7虚拟机、一台CentOS 7虚拟机、两台c3725路由设备。首先添加两台路由设备,并在路由设备上添加磁盘空间方便我们创建vlan,添加2层交换接口,方便我们把路由设备做成一个3层交换设备与一个2层交换设备。添加三台host主机,分别更名为DHC、win 10、win 7,这个时候还需要我们在VMware 15虚拟机设备中添加两块虚拟网卡,设知道仅主机模式,这个时候在重新回到GNS3中使用链接线将设备接起来,这个实验中我们将划分3个vlan,分别将3台虚拟机划分到不同的vlan中(vlan地址划分:vlan10:192.168.10.1/24、vlan20:192.168.20.1/24、vlan100:192.168.100.1/24,给DHCP服务器指定静态IP地址 192.168.100.100。如下图所示:
2、打开VMware 15,开启win 10、win 7、CentOS 7虚拟机,在CentOS 7虚拟机中安装DHCP服务;安装完成后分别给win 10、win 7、CentOS 7虚拟机绑定网卡,win 10绑定VMnet2网卡,win 7绑定VMnet3网卡CentOS 7绑定VMnet1网卡;然会回到CentOS 7中配置静态路由、配置DHCP服务,完成后开启服务,关闭防火墙,关闭增强性安全文件。
[root@localhost ~]# yum install dhcp -y //安装DHCP服务
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): base/7/x86_64/primary_db | 6.0 MB 00:00:01
...//省略部分内容...
[root@localhost ~]# ifconfig //查看网卡信息
ens33: flags=4163 mtu 1500 //此时无法获取IP地址
inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20
ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet)
RX packets 47 bytes 30451 (29.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 122 bytes 13596 (13.2 KiB)
...//省略部分内容...
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 //进入ens33网卡配置文件
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static //更改dhcp为static配置静态IP地址
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=2ef6b862-5201-48c5-a450-23b3720ab3a0
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.100 //配置IP地址
NETMASK=255.255.255.0 //配置子网掩码
GATEWAY=192.168.100.1 //配置网关
~
~
:wq //保存退出
[root@localhost ~]# service network restart //重新启动网络服务
Restarting network (via systemctl): [ 确定 ]
[root@localhost ~]# ifconfig //查看网卡信息
ens33: flags=4163 mtu 1500 //获取静态IP地址
inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20
ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet)
RX packets 48 bytes 30694 (29.9 KiB)
...//省略部分内容...
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf //进入dhcp服务主配置文件
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example //显示dhcp配置文件模板位置
# see dhcpd.conf(5) man page
#
~
...//省略部分内容...
~
:r /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example //将dhcpd配置文件模板写入主配置文件
//写入的著配置文件:
#
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 10.152.187.0 netmask 255.255.255.0 {
} //主要在此处做出更改
# This is a very basic subnet declaration.
subnet 10.254.239.0 netmask 255.255.255.224 {
range 10.254.239.10 10.254.239.20;
option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}
//更改后的配置文件信息:
...//省略部分内容...
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 192.168.100.0 netmask 255.255.255.0 { //更改IP网段
range 192.168.100.100 192.168.100.200; //可以分配的IP地址范围
option routers 192.168.100.1; //网关信息(注意,每段结束以;结尾)
} //注意最后的大括号不可删除,否则服务无法开启
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200; //添加vlan 10网段的地址分配条目
option routers 192.168.10.1;
}
subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.100 192.168.20.200; //添加vlan 20网段的地址分配条目
option routers 192.168.20.1;
}
# This is a very basic subnet declaration.
:wq //保存退出
//因为我们这边设置了三个vlan,网段都不相同,所以三个网段都要添加
[root@localhost ~]# systemctl start dhcpd //开启dhcp服务
[root@localhost ~]# systemctl status dhcpd //查看服务是否开启
dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2019-09-04 22:56:05 CST; 14s ago //服务成功开启
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 5343 (dhcpd)
Status: "Dispatching packets..."
CGroup: /system.slice/dhcpd.service
└─5343 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhc...
9月 04 22:56:05 localhost.localdomain dhcpd[5343]: No subnet declaration for virbr....
...//省略部分内容...
9月 04 22:56:05 localhost.localdomain systemd[1]: Started DHCPv4 Server Daemon.
Hint: Some lines were ellipsized, use -l to show in full.
3、DHCP服务开启后我们回到GNS3中,开启添加的3层交换机与2层交换机,并双击进入3层交换设备与2层交换设备,在2层交换设备中配置vlan,并将接入链路分别接入相对应的vlan中,将f1/0接口配置为trunk链路,在3层交换设备中同样设置vlan,然后进入vlan中配置IP地址,并指定IP地址192.168.100.100可以通过vlan在局域网中通信,最后将f1/0接口同样配置为trunk链路。
sw2#conf t //在2层交换设备中进入全局模式
Enter configuration commands, one per line. End with CNTL/Z.
sw2(config)#vlan 10,20,100 //配置vlan10、20、100
sw2(config-vlan)#ex //退出vlan接口
sw2(config)#do show vlan-sw b //查看vlna是否配置成功
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/1, Fa1/2, Fa1/3
Fa1/4, Fa1/5, Fa1/6, Fa1/7
Fa1/8, Fa1/9, Fa1/10, Fa1/11
Fa1/12, Fa1/13, Fa1/14, Fa1/15
10 VLAN0010 active
20 VLAN0020 active //配置的vlan
100 VLAN0100 active
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
sw2(config)#int f1/1 //进入f1/1接口
sw2(config-if)#sw m acc //进入配置链路
sw2(config-if)#sw acc vlan 100 //将链路接入vlan100
sw2(config-if)#ex //退出
sw2(config)#int f1/2 //进入f1/2接口
sw2(config-if)#sw m acc //进入配置链路
sw2(config-if)#sw acc vlan 10 //将链路接入vlan10
sw2(config-if)#ex //退出
sw2(config)#int f1/3 //进入f1/3接口
sw2(config-if)#sw m acc //进入配置链路
sw2(config-if)#sw acc vlan 20 //将链路接入vlan20
sw2(config-if)#ex //退出
sw2(config)#do show vlan-sw b //查看vlna
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/4, Fa1/5, Fa1/6
Fa1/7, Fa1/8, Fa1/9, Fa1/10
Fa1/11, Fa1/12, Fa1/13, Fa1/14
Fa1/15
10 VLAN0010 active Fa1/2
20 VLAN0020 active Fa1/3 //链路成功接入vlan
100 VLAN0100 active Fa1/1
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
sw2(config)#int f1/0 //进入f1/0接口
sw2(config-if)#sw m t //将接口配置为trunk
sw2(config-if)#sw t en do //在trunk链路中封装dot1q协议
sw2(config-if)#ex //退出
sw2(config)#do show int f1/0 switchport //查看接口是否配置成功
Name: Fa1/0
Switchport: Enabled
Administrative Mode: trunk //成功配置trunk链路
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: Disabled
Access Mode VLAN: 0 ((Inactive))
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 1,10,20,100
Protected: false
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none
Appliance trust: none
sw2(config)#no ip routing //关闭2层交换设备路由功能
sw3(config)#vlan 10,20,100 //在3层交换设备中配置vlan10、20、100
sw3(config-vlan)#ex //退出
sw3(config)#do show vlan-sw b //查看vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/1, Fa1/2, Fa1/3
Fa1/4, Fa1/5, Fa1/6, Fa1/7
Fa1/8, Fa1/9, Fa1/10, Fa1/11
Fa1/12, Fa1/13, Fa1/14, Fa1/15
10 VLAN0010 active
20 VLAN0020 active //配置成功
100 VLAN0100 active
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
sw3(config)#int vlan 10 //进入虚拟接口vlan10
sw3(config-if)#ip add 192.168.10.1 255.255.255.0 //在接口中添加IP地址
sw3(config-if)#ip helper-address 192.168.100.100 //指定IP地址192.168.100.100可通过接口
sw3(config-if)#no shut //开启配置
sw3(config-if)#ex //退出
sw3(config)#int vlan 20 //进入虚拟接口vlan20
sw3(config-if)#ip add 192.168.20.1 255.255.255.0 //在接口中添加IP地址
sw3(config-if)#ip helper-address 192.168.100.100 //指定IP地址192.168.100.100可通过接口
sw3(config-if)#no shut //开启配置
sw3(config-if)#ex //退出
sw3(config)#int vlan 100 //进入虚拟接口vlan100
sw3(config-if)#ip add 192.168.100.1 255.255.255.0 //在接口中添加IP地址
sw3(config-if)#ip helper-address 192.168.100.100 //指定IP地址192.168.100.100可通过接口
sw3(config-if)#no shut //开启配置
sw3(config-if)#ex //退出
sw3(config)#int f1/0 //进入f1/0 接口
sw3(config-if)#sw m t //配置为trunk链路
*Mar 1 00:22:18.607: %DTP-5-TRUNKPORTON: Port Fa1/0 has become dot1q trunk
*Mar 1 00:22:19.111: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
*Mar 1 00:22:19.119: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
*Mar 1 00:22:19.127: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan100, changed state to up
sw3(config-if)#sw t en do //封装协议
sw3(config-if)#ex //突出
sw3(config)#do show int f1/0 switchport //查看trunk是否配置成功
Name: Fa1/0
Switchport: Enabled
Administrative Mode: trunk //成功配置trunk链路
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: Disabled
Access Mode VLAN: 0 ((Inactive))
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 1,10,20,100
Protected: false
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none
Appliance trust: none
sw3(config)#do show ip int b //查看IP地址是否配入vlan,是否开启
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset administratively down down
FastEthernet0/1 unassigned YES unset administratively down down
FastEthernet1/0 unassigned YES unset up up
FastEthernet1/1 unassigned YES unset up down
...//省略部分内容...
FastEthernet1/14 unassigned YES unset up down
FastEthernet1/15 unassigned YES unset up down
Vlan1 unassigned YES unset up up
Vlan10 192.168.10.1 YES manual up up
Vlan20 192.168.20.1 YES manual up up
Vlan100 192.168.100.1 YES manual up up
//成功配入,并开启
4、完成配置后我们来查看虚拟机客户端win 10、win 7是否自动获取IP地址
5、下面我们来给win 10 客户机指定固定的IP地址,首先在win 10客户机中获取win 10客户机网卡的MAC地址,然后会的CentOS 7系统中进入DHCP配置文件中进行设置