四、案例动态分配IP地址
4.1网络配置
4.1.1修改网卡
[root@localhost ~]#yum install dhcp -y [root@localhost ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=“Ethernet” PROXY_METHOD=“none” BROWSER_ONLY=“no” BOOTPROTO=“static” 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=“0ba12236-1264-4a1c-8536-88dd89f47c19” DEVICE=“ens33” ONBOOT=“yes” IPADDR=“192.168.100.100” PREFIX=“24” GATEWAY=“192.168.100.254” IPV6_PRIVACY=“no”
4.1.2在虚拟机设置里选择自定义虚拟网络VMnet1
4.1.3在本机电脑网络里更改网络VMnet1的适配器
4.1.4在虚拟机上查看重启网卡看是否成功
4.2DHCP配置
4.2.1配置前先拷贝并配置
[root@localhost ~]# cp -p /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
4.2.2重启DHCP服务并查看状态
4.3ensp配置
4.3.1二层交换机
undo terminal monitor
Info: Current terminal monitor is off.
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname SW2
[SW2]int e0/0/2
[SW2-Ethernet0/0/2]q
[SW2]vlan batch 10 20 100
Info: This operation may take a few seconds. Please wait for a moment…done.
[SW2]int e0/0/2
[SW2-Ethernet0/0/2]p l a
[SW2-Ethernet0/0/2]p d v 10
[SW2-Ethernet0/0/2]int e0/0/3
[SW2-Ethernet0/0/3]p l a
[SW2-Ethernet0/0/3]p d v 20
[SW2-Ethernet0/0/3]int e0/0/4
[SW2-Ethernet0/0/4]p l a
[SW2-Ethernet0/0/4]p d v 100
[SW2-Ethernet0/0/4]int e0/0/5
[SW2-Ethernet0/0/5]p l a
[SW2-Ethernet0/0/5]p d v 100
[SW2-Ethernet0/0/5]q
[SW2]int e0/0/1
[SW2-Ethernet0/0/1]p l t
[SW2-Ethernet0/0/1]p t a v a
4.3.2三层交换机配置
undo terminal monitor
Info: Current terminal monitor is off.
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname SW1
[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l t
[SW1-GigabitEthernet0/0/1]p t a v a
[SW1-GigabitEthernet0/0/1]q
[SW1]vlan batch 10 20 100
[SW1]int Vlanif 10
[SW1-Vlanif10]ip add 192.168.1.254 24
[SW1-Vlanif10]q
[SW1]int Vlanif 20
[SW1-Vlanif20]ip add 192.168.2.254 24
[SW1-Vlanif20]q
[SW1]int Vlanif 100
[SW1-Vlanif100]ip add 192.168.100.254 24
[SW1-Vlanif100]q
[SW1]ping 192.168.100.100
PING 192.168.100.100: 56 data bytes, press CTRL_C to break
Reply from 192.168.100.100: bytes=56 Sequence=1 ttl=64 time=130 ms
Reply from 192.168.100.100: bytes=56 Sequence=2 ttl=64 time=60 ms
Reply from 192.168.100.100: bytes=56 Sequence=3 ttl=64 time=60 ms
Reply from 192.168.100.100: bytes=56 Sequence=4 ttl=64 time=60 ms
Reply from 192.168.100.100: bytes=56 Sequence=5 ttl=64 time=30 ms
[SW1]dhcp enable #开启DHCP之后再配置
[SW1]int Vlanif 10
[SW1-Vlanif10]dhcp select relay #DHCP中继选择
[SW1-Vlanif10]dhcp relay server-ip 192.168.100.100 #DHCP中继服务器IP地址
[SW1-Vlanif10]q
[SW1]int Vlanif 20
[SW1-Vlanif20]dhcp select relay
[SW1-Vlanif20]dhcp relay server-ip 192.168.100.100
[SW1-Vlanif20]q
[SW1] User interface con0 is available
4.4测试
五、总结
DHCP的定义以及好处
DHCP的分配方式:自动分配,手动分配,动态分配
DHCP的工作原理:
DHCP 客户端进行 IP 请求
DHCP 服务器响应请求
DHCP 客户机选择 IP
DHCP 服务器确认租约