系统相关
首页 > 系统相关> > Linux:配置dhcp服务器和dhcp中继

Linux:配置dhcp服务器和dhcp中继

作者:互联网

配置dhcp服务器

在昨天的基础上通过yum安装dhcp服务
在这里插入图片描述
在这里插入图片描述
把dhcpd.conf.example内容覆盖进dhcpd.conf文件中

[root@localhost ~]# cp -p /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y

进入配置文件dhcpd.conf在56行添加subnet,然后运行dhcpd服务

 56 subnet 192.168.214.0 netmask 255.255.255.0 {
 57 range 192.168.214.10 192.168.214.210;
 58 option routers 192.168.214.214;
 59 }
 :wq
 [root@localhost ~]# systemctl start dhcpd

可以发现windows获取了192.168.214.0网段的一个ip地址
在这里插入图片描述

dhcp服务器配置固定ip地址

查看windows网卡的mac地址
在这里插入图片描述

进入配置文件dhcpd.conf,修改78行至81行的内容,host后面跟主机名,名字任意起,hardware ethernet后面跟目标mac地址,fixed-address跟分配的固定ip地址,修改后重启dhcpd服务。

 78 host shiki {
 79   hardware ethernet 00:0C:29:EF:70:9A;
 80   fixed-address 192.168.214.211;
 81 }
 [root@localhost ~]# systemctl restart dhcpd

释放原本的ip地址
在这里插入图片描述
再重新获取ip地址
在这里插入图片描述

配置dhcp中继

在这里插入图片描述
LSW1的配置

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys sw1
[sw1]undo info	
[sw1]undo info-center en
Info: Information center is disabled.
[sw1]vlan batch 10 20 30    //添加vlan
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw1]inter e0/0/1
[sw1-Ethernet0/0/1]p l a           //进入端口为每个接口设置接口模式access
[sw1-Ethernet0/0/1]p d v 10        //并设置vlan
[sw1-Ethernet0/0/1]
[sw1-Ethernet0/0/1]inter e0/0/2
[sw1-Ethernet0/0/2]p l a
[sw1-Ethernet0/0/2]p d v 20
[sw1-Ethernet0/0/2]inter e0/0/3
[sw1-Ethernet0/0/3]p l a
[sw1-Ethernet0/0/3]p d v 30
[sw1-Ethernet0/0/3]inter e0/0/4
[sw1-Ethernet0/0/4]p l t
[sw1-Ethernet0/0/4]p t a v a
[sw1-Ethernet0/0/4] User interface con0 is available

LSW2的配置

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info	
[Huawei]undo info-center en
Info: Information center is disabled.
[Huawei]sys sw2
[sw2]vlan batch 10 20 30
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw2]inter g0/0/1
[sw2-GigabitEthernet0/0/1]p l t
[sw2-GigabitEthernet0/0/1]p t a v a
[sw2-GigabitEthernet0/0/1]inter vlan 10
[sw2-Vlanif10]ip address 192.168.10.1 24
[sw2-Vlanif10]ip address 192.168.20.1 24
[sw2-Vlanif10]ip address 192.168.10.1 24
[sw2-Vlanif10]inter vlan 20
[sw2-Vlanif20]ip address 192.168.20.1 24
[sw2-Vlanif20]inter vlan 30
[sw2-Vlanif30]ip address 192.168.214.1 24
[sw2-Vlanif30] User interface con0 is available
[sw2]dhcp enable      //开启dhcp
Info: The operation may take a few seconds. Please wait for a moment.done.
[sw2]inter vlan 10
[sw2-Vlanif10]dhcp select relay          //在接口处开启dhcp中继
[sw2-Vlanif10]inter vlan 20
[sw2-Vlanif20]dhcp select relay
[sw2-Vlanif20]inter vlan 30
[sw2-Vlanif30]dhcp select relay
[sw2-Vlanif30]dhcp relay server-ip 192.168.214.214        //给接口设置dhcp服务器的地址
[sw2-Vlanif30]inter vlan 20
[sw2-Vlanif20]dhcp relay server-ip 192.168.214.214
[sw2-Vlanif20]inter vlan 10
[sw2-Vlanif10]dhcp relay server-ip 192.168.214.214

在dhcp的配置文件/etc/dhcp/dhcpd.conf中添加下面的东西,subnet后跟要分配ip地址的pc的网段,range后跟ip地址池,option routers后跟指向的网关,最后再重启一下dhcpd服务

subnet 192.168.214.0 netmask 255.255.255.0 {
range 192.168.214.10 192.168.214.210;
option routers 192.168.214.214;
}

subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.10 192.168.10.30;
option routers 192.168.10.1;
}

subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.10 192.168.20.30;
option routers 192.168.20.1;
}
[root@localhost ~]# systemctl restart dhcpd

最后重新申请一下pc的ip地址发现pc获得了ip地址
在这里插入图片描述
在这里插入图片描述

标签:中继,ip,192.168,dhcpd,Linux,sw1,dhcp,sw2
来源: https://blog.csdn.net/Ryougi_Shiki_uio/article/details/117076130