DHCP三种配置

一 DHCP分配客户机IP地址

[[email protected] ~]# rpm -q dhcp //检查dhcp服务是否安装
[[email protected] ~]# mount /dev/cdron /media
[[email protected] ~]# cd /media/Packages
[[email protected] ~]# rpm -ivh dhcp-4.2.5-36.e17.centos.x86_64.rpm
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
~ [[email protected] ~]# cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example >
/etc/dhcp/dhcpd.conf [[email protected] ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "localhost";
option domain-name-servers 202.106.0.20,8.8.8.8; //DNS解析

default-lease-time 360; //IP地址默认租约
max-lease-time 7200; //IP最大租约时间
subnet 192.168.200.0 netmask 255.255.255.0 { //网段 和子网掩码
range 192.168.200.180 192.168.200.200; //分配IP地址地址池
option routers 192.168.200.1; //网关
}
[[email protected] ~]# systemctl start dhcpd //开启dhcp服务
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728

TYPE=Ethernet
BOOTPROTO=dhcp //修改
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777728
DEVICE=eno16777728
ONBOOT=yes //可以改
IPADDR=192.168.200.101
NETMASK=255.255.255.0
GATEWAY=192.168.200.1
DNS1=202.106.0.20
[[email protected] ~]# systemctl restart network //重启服务

     禁用并重启,活得地址池IP地址 (客户机要进入NET模式)

二DHCP固定IP地址

[

[email protected] ~]# cat /var/lib/dhcpd/dhcpd.leases    //查看租约信息并获取网卡信息

[[email protected] ~]# vim /etc/dhcp/dhcpd.conf

lease 192.168.200.15 {
starts 5 2019/08/16 07:37:52;
ends 5 2019/08/16 07:47:52;
tstp 5 2019/08/16 07:47:52;
cltt 5 2019/08/16 07:37:52;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:93:3e:e3;

添加

host win7 {
hardware ethernet 00:0c:29:93:3e:e3;
fixed-address 192.168.200.99;     //固定IP地址

若是win7客户机不成功 

cmd命令中输入 ipconfig  /release 释放IP

ipconfig /renew 获取IP

三  DHCP中继配置

需要 DHCP服务器一个 和两个网卡的DHCP中继

中继器的配置情况如下 :

[[email protected] ~]# mount /dev/cdron /media
[[email protected] ~]# cd /media/Packages
[[email protected] ~]# rpm -ivh dhcp-4.2.5-36.e17.centos.x86_64.rpm

[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728

删除网关和DNS

[[email protected] ~]#cp   /etc/sysconfig/network-scripts/ifcfg-eno16777728    /etc/sysconfig/network-scripts/ifcfg-eno33554960

[[email protected] ~]#vim /etc/sysconfig/network-scripts/ifcfg-eno33554960

修改并删除

[[email protected] ~]# systemctl restart network

 

 

[[email protected] ~]# dhcrelay 192.168.200.100    //开启本机中继服务

 

在DHCP服务器的配置:

[[email protected] ~]# vim /etc/dhcp/dhcpd.conf

添加这四行命令

subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.15 192.168.100.40;
option routers 192.168.100.1;
}    

[[email protected] ~]# systemctl restart dhcpd

[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728

 

 在中继器中ping

若要ping通   window 需要关闭防火墙

[[email protected] ~]# systemctl disable firewalld.service
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'            //关闭中继的防火墙

rm '/etc/systemd/system/basic.target.wants/firewalld.service'

 

猜你喜欢

转载自www.cnblogs.com/maoyanqing/p/11364997.html
0条评论
添加一条新回复