Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

A, DHCP works

1.DHCP Service Introduction

DHCP (Dynamic Host Configuration Protocol, Dynamic Host Configuration Protocol) is generally used in large local area network environment, the main role is to centralize the management, assign an IP address, the host to dynamic network environments to obtain an IP address, Gateway address, DNS server addresses and other information, and be able to enhance the utilization of addresses.

Benefits 2.DHCP services

(1) to reduce the workload of an administrator;
(2) prevent IP address conflicts;
(3) when a network change IP addresses, do not need to re-configure the IP address of each user; and
(4) improving the utilization of the IP address rate;
(5) easy to configure the client.

3.DHCP of distribution

(1) automatically assigned: to assign a - a permanent IP addresses after use;
(2) manually assigned: IP address by the DHCP server administrator specifically;
(3) Dynamic allocation: After releasing the IP using, for other clients use.

4.DHCP lease process

(1) The client requests an IP address (the Discover)

When a DHCP client starts, the client has no IP address, so the client wants to obtain a valid address via DHCP, this time the DHCP client broadcasts a DHCP Discover found that information to find the DHCP server.

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

(2) a server response (Offer Penalty for)

When the DHCP server receives information from the client IP address request, it looks into its own IP address pool if there is a legitimate IP address to the client, if there is, the DHCP server on this IP address to be marked to was added to the DHCP Offer message, the DHCP server then broadcasts a DHCP Offer message.

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

(3) Select the IP address of the client (Request)

DHCP client IP address extracted from a received DHCP Offer message, issue the IP address of DHCP server addresses are reserved, so that the address can not be allocated to another DHCP client. In a network environment may have more than one DHCP server, DHCP client to obtain multiple DHCP offer, it is necessary to select DHCP client IP one provided, and then broadcast a DHCP server to send request to tell all their own choice.

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

(4) determining the lease server (ACK)

DHCP server receives the DHCP Request message, in the form of DHCP ACK message to the client to confirm the success of the broadcast, the message contains the IP address and other information valid lease can be configured. When the client receives the DHCP ACK message, it is configured with an IP address, complete TCP / IP initialization.

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

(5) re-login

DHCP client log back into the network every time, no need to send a DHCP Discover message, but send it directly DHCP Request contains previous assigned IP address request information.

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

(6) lease renewal

When the DHCP server reaches 50% of the IP address lease rental clients, we need to update the lease. The client sends DHCP Request packet directly to the server lease request to update the existing address lease.

Two, DHCP relay service configuration

1. First, in the topology GNS3 set, and then connect the interface device according to FIG.

接口连接:
sw1:f1/0----------sw2:f1/0
sw1:f1/1----------DHCP:VMnet1
sw1:f1/2----------win10:VMnet2
sw1:f1/3----------server:VMnet8
vlan分配:
win10:vlan 10
server:vlan 20
DHCP:vlan 100
网段分配:
win10:192.168.10.0/24
server:192.168.20.0/24
DHCP:192.168.100.0/24
Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

2.在Linux系统用yum源安装DHCP服务。注意:需要在联网环境下安装。

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

3.将win10系统的网络模式,选择为自定义并绑定VMnet1网卡。

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

4.将server系统的网络模式,选择为自定义并绑定VMnet2网卡。

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

5.将Linux系统的网络模式,选择为自定义并绑定VMnet8网卡。

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

6.点击“编辑”选择“虚拟网络编辑器”,然后选择“更改设置”,再选择“VMnet8”网卡将改为仅主机模式,并将“使用本地DHCP服务分配IP地址”选项的“√”去掉。(4、5、6步是为了创造一个局域网内没有DHCP服务器的实验环境)

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)
Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)
Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

7.进入Linux系统,用vim编辑器对网卡“ens33”的配置文件进行编辑,给它配置一个固定IP。

输入:vim  /etc/sysconfig/network-scripts/ifcfg-ens33
将dhcp改为static
添加:
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)
Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

8.更改完网卡“ens33”的配置后,重启网络服务,再查看网卡信息,可以看到IP地址设置成功。

输入:service network restart 
输入:ifconfig

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

9.我们将系统给的DHCP配置文件的模板“/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example”,复制到DHCP服务的配置文件“/etc/dhcp/dhcpd.conf”中,并将其覆盖。

输入:cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

10.用vim编辑器对DHCP服务的配置文件“/etc/dhcp/dhcpd.conf”进行配置。在里面添加三个网段的DHCP服务。

输入:vim /etc/dhcp/dhcpd.conf
添加:
subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.50 192.168.10.100;
  option routers 192.168.10.1;
}

subnet 192.168.20.0 netmask 255.255.255.0 {
  range 192.168.20.50 192.168.20.100;
  option routers 192.168.20.1;
}

subnet 192.168.100.0 netmask 255.255.255.0 {
  range 192.168.100.50 192.168.100.100;
  option routers 192.168.100.1;
}

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)
Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

11.开启dhcp服务,并查看服务状态。

输入:systemctl start dhcpd
输入:systemctl status dhcpd

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

12.进入GNS3将所有设备开启。

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

13.双击sw1,打开sw1的配置面板。进入全局模式,然后关闭路由功能。

输入:conf t
输入:no ip routing

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

14.新建三个vlan,分别为vlan 10、vlan 20、vlan 100。然后查看vlan是否添加成功。

输入:vlan 10,20,100
输入:do show vlan-sw b
输入:exit

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

15.分别进入f1/1、f1/2、f1/3接口,将接口模式设置为“access”模式,然后将三个接口分别添加到vlan 100、vlan 10、vlan 20。再进入f1/0接口,将f1/0接口模式设置为“trunk”模式,trunk封装类型设置为“dot1q”。

输入:int f1/1
输入:switch mode access
输入:switch access vlan 100
输入:exit
输入:int f1/2
输入:switch mode access
输入:switch access vlan 10
输入:exit
输入:int f1/3
输入:switch mode access
输入:switch access vlan 20
输入:exit
输入:int f1/0
输入:switch mode trunk
输入:switchport trunk encapsulation dot1q
输入:exit

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

16.双击sw2设备,打开sw2的配置面板。先进入全局模式,再新建三个vlan,vlan 10、vlan 20、vlan 100。然后查看是否添加成功。

输入:conf t
输入:vlan 10,20,100
输入:exit
输入:do show vlan-switch brief

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

17.进入f1/0接口,将f1/0接口模式设置为“trunk”模式,trunk封装类型设置为“dot1q”。

输入:int f1/0
输入:switch mode trunk
输入:switchport trunk encapsulation dot1q
输入:exit

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

18.分别进入vlan 10、vlan 20、vlan 100,设置它们的网关地址并开启。

输入:int vlan 10
输入:ip add 192.168.10.1 255.255.255.0
输入:no shutdown
输入:exit
输入:int vlan 20
输入:ip add 192.168.20.1 255.255.255.0
输入:no shutdown
输入:exit
输入:int vlan 100
输入:ip add 192.168.100.1 255.255.255.0
输入:no shutdown
输入:exit

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

19.查看一下,IP地址是否设置成功。

输入:do show ip int brief
Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

20.分别进入vlan 10、vlan 20、vlan 100中,然后给它们设置DHCP服务器的IP地址。

输入:int vlan 10
输入:ip helper-address 192.168.100.100
输入:no shutdown
输入:exit
输入:int vlan 20
输入:ip helper-address 192.168.100.100
输入:no shutdown
输入:exit
输入:int vlan 100
输入:ip helper-address 192.168.100.100
输入:no shutdown
输入:exit

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

21.进入win10系统,先释放掉之前获取的IP地址,再重新获取IP地址。结果成功获取到DHCP服务器分配的IP地址192.168.10.50。

输入:ipconfig /release
输入:ipconfig /renew

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

22.用“ipconfig /all”命令,查看一下DHCP服务器的地址。就是192.168.100.100。

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

23.进入server系统,先释放掉之前获取的IP地址,再重新获取IP地址。结果成功获取到DHCP服务器分配的IP地址192.168.20.51。

输入:ipconfig /release
输入:ipconfig /renew

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

23.用“ipconfig /all”命令,查看一下DHCP服务器的地址。就是192.168.100.100。

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

24. A system for win10, specify a fixed IP address. First with "ipconfig / all" command, look win10 MAC address.

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

25. The system of re-entering the Linux DHCP service configuration file, which set a fixed IP address for win10 192.168.10.10

输入:vim /etc/dhcp/dhcpd.conf
添加:
host fantasia {
  hardware ethernet 00:0C:29:1E:27:9B;
  fixed-address 192.168.10.10;
}

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

26. Restart the DHCP service.

输入:systemctl restart dhcpd

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

27. re-enter the win10 system, the first freed IP address obtained prior to re-obtain an IP address. The results obtained with success DHCP server to assign a fixed IP address 192.168.10.10.

输入:ipconfig /release
输入:ipconfig /renew

Small experiments: Based on GNS3 and VMware with Linux CentOS7 set up DHCP relay service (+ principle experiment)

Guess you like

Origin blog.51cto.com/14449541/2434621