Linux, set up DHCP relay service (full high-energy !!!)

lab environment:

virtual machine

  • A Linux system server do DHCP server

  • Two win10 client

GNS3 virtual network software

Purpose:

In gns3 the analog implementation of DHCP relay service

 

(A) first with vmnet8 NAT network mode to install the DHCP service on a Linux system

1, using the yum repository Download dhcp service

[Root @ localhost ~] # yum install dhcp -y install dhcp service

Picture 1.png

2, all installed after the vmnet1,2,8 switched to the master mode only, the modified vmnet8 nat only mode to master mode and the automatic allocation dhcp local virtual closed network editor on the virtual machine

Picture 1.png

(B) build a service infrastructure in gns3 in which to configure a device

1, open structures gns3 two hosts, a server, a Layer 2 switching, a three switches. (Change the device to two, three boards, set sw2, sw3 device name, set the disk space 128MB, add Layer 2 services board) specific settings seen previously

2, the devices are connected as follows:

win1 sw2 is coupled to the vmnet2 f1 / 2

win2 sw2 is coupled to the vmnet8 f1 / 3

dhcp sw2 is coupled to the vmnet1 f1 / 1

sw2 of f1 / 0 is connected to sw3 f1 / 0

Setup is complete and fully open and display the port number

Picture 1.png

3, double-click to open the Layer 2 sw2 exchange division vlan

win10-1:vlan10 192.168.10.1/24

win10-2:vlan20 192.168.20.1/24

dhcp:vlan100 192.168.100.1/24

Double-click to open sw2 configure vlan

f1/1:vlan100

f1/2:vlan10

f1/3:vlan20

sw2#configure terminal  进入全局模式
sw2(config)#vlan 10,20,100   创建三个vlan
sw2(config-vlan)#ex  退出vlan
sw2(config)#do show vlan-switch brief  查看创建的vlan的信息

Picture 1.png

sw2(config)#interface f1/1          进入f1/1的接口模式
sw2(config-if)#switch mod access    设置access模式
sw2(config-if)#switch access vlan 100  将端口分配给vlan100中
sw2(config-if)#ex
sw2(config)#interface f1/2          设置f1/2的接口模式
sw2(config-if)#switch mod access
sw2(config-if)#switch access vlan 10
sw2(config-if)#ex
sw2(config)#interface f1/3          设置f1/3的接口模式
sw2(config-if)#switch mod access
sw2(config-if)#switch access vlan 20
sw2(config-if)#ex
sw2(config)#do show vlan-sw b   查看vlan的划分信息

Picture 1.png

sw2(config)#interface f1/0   进入f1/0接口
sw2(config-if)#switch mod trunk   设置中继链路模式
sw2(config-if)#switch trunk encapsulation dot1q   选择封装类型为dot1q
sw2(config-if)#ex
sw2(config)#no ip routing   关闭路由功能
sw2(config)#do show int f1/0 switchport  查看接口f1/0的接口信息

Picture 1.png

4,双击打开sw3三层交换机进行配置

创建三个vlan10,20,100

将f1/0接口设置为trunk链路

设置vlan10的网关子网掩码192.168.10.1 255.255.255.0

设置vlan20的网关子网掩码192.168.20.1 255.255.255.0

设置vlan100的网关子网掩码 192.168.100.1 255.255.255.0

sw3(config)#vlan 10,20,100  创建三个vlan
sw3(config-vlan)#ex     退出
sw3(config)#do show vlan-sw b  查看创建的vlan的信息

Picture 1.png

sw3(config)#int f1/0   进入接口f1/0
sw3(config-if)#switch mod trunk   设置为trunk链路
sw3(config-if)#switch trunk encapsulation dot1q  选择封装的类型
sw3(config-if)#ex  退出
sw2(config)#do show int f1/0 switchport   查看接口f1/0接口的信息

Picture 1.png

sw3(config)#int vlan 10                进入vlan10
sw3(config-if)#ip add 192.168.10.1 255.255.255.0  设置vlan10的网关及子网掩码
sw3(config-if)#no shut   开启vlan10
sw3(config-if)#ex
sw3(config)#int vlan 20    设置vlan20 
sw3(config-if)#ip add 192.168.20.1 255.255.255.0
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
sw3(config-if)#no shut

Picture 1.png

sw3(config-if)#end
sw3#show ip interface brief   查看vlan设置的网关信息

Picture 1.png

Picture 1.png

(三)配置Linux系统的dhcp服务器

1,先将Linux系统的ip更改为一个静态的地址

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33   设置ens33的网卡信息设置一个静态的IP地址

Screenshot micro-channel _20190831184823.png

[root@localhost ~]# systemctl restart network.service  重启网络服务
[root@localhost ~]# ifconfig  查看当前的网卡信息

Picture 1.png

2,复制一份dhcp配置文件的模板到/etc目录下

[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf  复制一份dhcp的配置文件模板到etc下
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf   设置dhcp的配置文件

Screenshot micro-channel _20190831184823.png

[root@localhost ~]# systemctl start dhcpd   开启dhcp服务
[root@localhost ~]# systemctl status dhcpd  查看dhcp服务状态信息

Screenshot micro-channel _20190831184823.png

(四)在网关中配置DHCP中继

sw3#conf t  进入全局模式
sw3(config)#int vlan 10     设置网关中的DHCP中继
sw3(config-if)#ip helper-address 192.168.100.100
sw3(config-if)#no shut
sw3(config-if)#ex
sw3(config)#int vlan 20
sw3(config-if)#ip helper-address 192.168.100.100
sw3(config-if)#no shut
sw3(config-if)#ex
sw3(config)#int vlan 100
sw3(config-if)#ip helper-address 192.168.100.100
sw3(config-if)#no shut

Screenshot micro-channel _20190901020200.png

(五)在win1和win2客户机中获取DHCP自动分配的地址

1,打开win10-1的网络更改为自动获取IP地址

2,打开cmd命令输入命令ipconfig,查看ip地址(192.168.10.182),成功获取

Screenshot micro-channel _20190901020446.png

Screenshot micro-channel _20190901020714.png

3,打开win10-2的网络更改为自动获取IP地址

4,打开cmd命令输入命令ipconfig,查看ip地址(192.168.20.182),成功获取

5,使用ping测试是否和DHCP服务器互联互通,实验成功

Screenshot micro-channel _20190901020446.png

Screenshot micro-channel _20190901020821.png

微信截图_20190901021748.png

实验结果:成功利用linux系统中的DHCP中继服务,自动分配不同网段内ip范围中的地址


扩展:如何利用DHCP服务固定给某客户机一个固定的IP地址?

1,打开win10-1客户机,使用ipconfig /all查看网卡的MAC地址并复制

微信截图_20190901022238.png

2. Open a Linux system, edit dhcp server configuration file, and restart the service

[root @ localhost ~] # vim /etc/dhcp/dhcpd.conf edit information fixed IP assigned to dhcp configuration file 
[root @ localhost ~] # systemctl restart dhcpd.service restart the dhcp service

微信截图_20190901022638.png

3, in win10-1 client test results

ipconfig / release to release the original IP address 
ipconfig / renew IP address and obtain

微信截图_20190901022842.png

The results: the success of obtaining a fixed IP address, a successful experiment



thanks for reading

!!!

Guess you like

Origin blog.51cto.com/14080162/2434452