-------------DHCP主机给客户端分配IP udp67-------------
主机操作:
1.#yum install dhcp -y [安装dhcp服务]
2.#cat /usr/share/doc/dhcp-*/dhcpd.conf.example | grep -v ^# > /etc/dhcp/dhcpd.conf [将usr下模板拷贝至etc下配置文件]
3.#vim dhcpd.conf [修改etc下的dhcpd.conf文件]---每次修改配置文件后都需要重启DHCP服务
4.subent 192.168.10.0[本机ip地址段] netmask 255.255.255.0 {
range 192.168.10.60 192.168.10.70;
option domain-name-servers 8.8.8.8;
option domain-name "ck007"
option routers 192.168.10.2;[设定网关]
option broadcast-address 192.168.10.255[设定广播地址]
default-lease-time 600;[可以不设定]
max-lease-time 7200;
}
5.#systemctl restart dhcpd [重启DHCP服务]
#systemctl status dhcpd [查看DHCP服务]
客户端操作:
1.#yum install dhclient -y [安装dhcp客户端]
2.#dhclient -v [自动获取DHCP IP地址]----确保网卡没有设置ip地址
3.#dhclient -r [清楚获取到的DHCP地址]
-----------------DHCP中继器跨子网分配IP----------------------
中继器操作:网卡1和服务器同一ip段 网卡2和客户端同一ip段
1.#yum install dhcp -y [安装DHCP服务]
#nmtui [设定网卡ip地址]
#systemctl restart network [重启网络配置]
2.#systemctl daemon-reload
#systemctl start dhcrelay [启动中继器]
3.#vim /usr/lib/systemd/system/dhcrelay.service [添加网卡]
ExecStart=/usr/sbin/dhcrelay -d --no-pid -i eno16777736 -i eno33554984 192.168.10.2(服务器ip地址)
4.#echo 1 〉/proc/sys/net/ipv4/ip_forward [将网卡启动]
5.#systemctl daemon-reload
#systemctl restart dhcrelay [重启中继器]
6.将192.168.10.1(服务器网卡)和192.168.10.2(中继器网卡1) [设置为Lan1同一子网]
将192.168.20.2(中继器网卡2)和192.168.20.3(客户端网卡)[设置为Lan2同一子网]
7.#route add default gw 192.168.20.2 [为客户端指定网关到中继器]
8.#nmtui[取消客户端ip并改为自动获取]
9.#systemctl restart network [重启网络配置]
10.#dhclient -v [自动获取DHCP IP地址]----确保网卡没有设置ip地址
服务器操作:
1.#vim dhcpd.conf [修改etc下的dhcpd.conf文件]---每次修改配置文件后都需要重启DHCP服务
2.subent 192.168.20.0[指向客户端网卡地址段] netmask 255.255.255.0 {
range 192.168.20.50 192.168.20.60;[指定范围]
option routers 192.168.20.2;[设定网关(网卡ip)]
option domain-name-servers 8.8.8.8;
}
3.#route add default gw 192.168.10.2 [为服务器设定网关到中继器]
-------------------------分配固定IP------------------------------
服务器操作:
1.#vim dhcpd.conf [修改etc下的dhcpd.conf文件]---每次修改配置文件后都需要重启DHCP服务
2.host snow {
hardware ethernet 00:0c:29:9d:fa:ee;
fixed-address 192.168.20.55;
}
3.客户端测试
#dhclient -v [自动获取DHCP IP地址]