1.DHCP概述
DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)
由Internet工作任务小组设计开发的
专门用于为 TCP/IP网络中的计算机自动分配TCP/IP参数的协议
2.使用DHCP的好处
减少管理员的工作量
避免输入错误的可能
避免IP地址冲突
当更改IP地址段时,不需要重新配置每个用户的IP地址
提高了IP地址的利用率
方便客户端的配置
3.DHCP的分配方式
自动分配:分配到一个IP地址后永久使用
手动分配:由DHCP服务器管理员专门指定IP地址
动态分配:使用完后释放该IP,供其它客户机使用
4.DHCP的租约过程
客户机从DHCP服务器获得IP地址的过程称为DHCP的租约过程:
5.使用DHCP动态配置主机地址
■ DHCP服务
● 为大量客户机自动分配地址,提供集中管理
●减轻管理和维护成本、提高网络配置效率
■ 可分配的地址信息主要包括
● 网卡的IP地址、子网掩码
● 对应的网络地址、广播地址
● 默认网关地址
● DNS服务器地址
配置
[root@localhost ~]# yum install -y dhcp
安装DHCP服务
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
复制一份更详细的配置文件,起名dhcpd.conf,询问是否覆盖选择yes
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0{
range 192.168.1.10 192.168.1.20;
option routers 192.168.1.2;
}
subnet 192.168.2.0 netmask 255.255.255.0{
range 192.168.2.10 192.168.2.20;
option routers 192.168.2.2;
}
subnet 192.168.100.0 netmask 255.255.255.0{
range 192.168.100.10 192.168.100.20;
option routers 192.128.100.2;
}
修改配置文件,设置资源池
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
启动dhcpd
[root@localhost ~]# cat /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=1dc2aa9d-9273-42d2-87a5-762b3b46ed5e
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.131
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
[root@localhost ~]#systemctl restart network
修改网卡信息
修改配置
修改ensp的配置
配置二层交换机
<Huawei>sys
[Huawei]sys SW1
[SW1]undo info-center enable
Info: Information center is disabled.
[SW1] vlan batch 10 20 100
[SW1-Ethernet0/0/1]port link-type access
[SW1-Ethernet0/0/1]port default vlan 100
[SW1-Ethernet0/0/1]undo shut
Info: Interface Ethernet0/0/1 is not shutdown.
[SW1-Ethernet0/0/1]int e0/0/2
[SW1-Ethernet0/0/2]p l a
[SW1-Ethernet0/0/2]p d v 10
[SW1-Ethernet0/0/2]undo shut
Info: Interface Ethernet0/0/2 is not shutdown.
[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]p l a
[SW1-Ethernet0/0/3]p d v 20
[SW1-Ethernet0/0/3]undo shut
Info: Interface Ethernet0/0/3 is not shutdown.
[SW1-Ethernet0/0/3]int e0/0/4
[SW1-Ethernet0/0/4]p l a
[SW1-Ethernet0/0/4]p d v 100
[SW1-Ethernet0/0/4]undo shut
Info: Interface Ethernet0/0/4 is not shutdown.
[SW1-Ethernet0/0/4]int e0/0/5
[SW1-Ethernet0/0/5]p l t
[SW1-Ethernet0/0/5]p t a v a
[SW1-Ethernet0/0/5]undo shut
Info: Interface Ethernet0/0/5 is not shutdown.
配置三层交换机
<Huawei>sys
[Huawei]sys SW2
[SW2]undo info-center enable
Info: Information center is disabled.
[SW2]v b 10 20 100
[SW2-GigabitEthernet0/0/1]p l t
[SW2-GigabitEthernet0/0/1]p t a v a
[SW2-GigabitEthernet0/0/1]undo shut
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[SW2]int v10
[SW2-Vlanif10]ip add 192.168.1.2 24
[SW2-Vlanif10]int v20
[SW2-Vlanif20]ip add 192.168.2.2 24
[SW2-Vlanif20]int v100
[SW2-Vlanif100]ip add 192.168.100.2 24
[SW2]dhcp enable
开启dhcp,否则后面会报错
[SW2]int v10
[SW2-Vlanif10]dhcp select relay
[SW2-Vlanif10]dhcp relay server-ip 192.168.100.2
[SW2-Vlanif10]int v20
[SW2-Vlanif20]dhcp select relay
[SW2-Vlanif20]dhcp relay server-ip 192.168.100.2
[SW2-Vlanif20]int v100
[SW2-Vlanif100]dhcp select relay
[SW2-Vlanif100]dhcp relay server-ip 192.168.100.2
三台ipv4的配置
在命令行输入
ipconfig /release
ipconfig /renew
显示ip地址完成: