Linux_DHCP&DHCP Relay

简介:

DHCP

DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议(计算机网络应用层协议 ),使用UDP协议工作。 
主要有两个用途:给内部网络或ISP(网络服务供应商)自动分配IP地址,给用户或者内部网络管理员作为对所有计算机作中央管理的手段。通常被应用在大型的局域网络环境中,主要作用是集中管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。 
DHCP协议采用客户端/服务器模型,主机地址的动态分配任务由网络主机(Client)驱动。当DHCP服务器接收到来自网络主机申请地址的信息时,才会向网络主机发送相关的地址配置等信息,以实现网络主机地址信息的动态配置。DHCP有3个端口,其中UDP 67(DHCPServer)和UDP 68(DHCPClient)为正常的DHCP服务端口;546号端口用于DHCPv6 Client,而不用于DHCPv4,是为DHCP failover服务,这是需要特别开启的服务,DHCP failover是用来做“双机热备”的。

DHCP Relay

DHCP Relay(DHCPR):DHCP中继服务,也叫做DHCP中继代理可以实现在不同子网和物理网段之间处理和转发dhcp信息的功能。如果DHCP客户机与DHCP服务器在同一个物理网段,则客户机可以正确地获得动态分配的ip地址。如果不在同一个物理网段,则需要DHCP Relay Agent(中继代理)。用DHCP Relay代理可以去掉在每个物理的网段都要有DHCP服务器的必要,它可以传递消息到不在同一个物理子网的DHCP服务器,也可以将服务器的消息传回给不在同一个物理子网的DHCP客户机。

Setup DHCPServer

Software: dhcp.x86.64 
ServiceName: dhcpd 
step1. Install dhcp

yum install -y dhcpd
  • 1
  • 1

step2. Service config file (DHCPServer use static IP)

cp /usr/share/doc/dhcp-4.1.1/dhcp.conf.sample /etc/dhcp/dhcpd.conf
  • 1
  • 1

vim /etc/dhcp/dhcpd.conf

#one networkSegment one subnet
subnet subnetIPsegment netmask subnetNetmask{ 
            range addressPool
            option domain-name-servers DNS1,DNS2
            option domain-name "domain.org" #default domain
            option routes routesIP
            default-lease-time leaseTime
            max-lease-time leaseTime
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

step3. Start DHCP server

service dhcpd start
netstat -lpntu | grep :67  #Ensure the DHCP service start successfully
  • 1
  • 2
  • 1
  • 2

Setup ClientPort

We can check the leaseFile,URL: /var/lib/dhcpd/dhcpd.leases 
可以在dhcpd.conf中设定,当client使用同一个IP到了租约的50%的时候,会再次的向DHCPServer发出请求要求续租,若此时DHCPServer关闭,ClientPort会有80%的时候再次发出请求要求续约。若达到了100%时间还没有得到DHCPServer的续约回应,则Client会再次的广播要求获取新的IP地址。如果网段中没有DHCPServer,HOST会为自己分配IP 169.254.0.0。

DHCP+DHCPRelay

Generally DHCPrelay and DHCP will bond in one server.Realize one DHCPServer satisfy more IP request of different networkSegment.DHCPRelayServer will receive the IP request of different networkSegment then give it to DHCP server deal with. 
service:dchrelay

Setup DHCPRelay service

step1. We need three networkCard and delete VMware own dhcp service. And set the static ip for networkCard. 
step2. Open system forward function. 
vim /etc/sysctl.conf

net.ipv4.ip_forward = 1
  • 1
  • 1

Load sysctl configuration

sysctl -p
  • 1
  • 1

step3. Set relay interface and DHCPServer IP. 
vim /etc.sysconfig/dhcrelay

INTERFACES="eth0 eth1 eth2"  #Relay interfacee
DHCPSERVERS="DHCPServerIP"
  • 1
  • 2
  • 1
  • 2

step4. Start dhcprelay service

service dhcrelay start
  • 1
  • 1

step5. Add three subnetSetting in the DHCPServer config file with /etc/dhcp/dhcpd.conf and restart service of dhcpd. 
step6. Setup the static route rules in the DHCPServer. 
Because the DHCPServer’s gatewayIP need assign to the internel gateway, so the DHCPRelayServer have to assign the route rules that the different subnetSegment computer can find the DHCPServer subnet interface. 
For example:

route add -net subnet1SegmentPool gw DHCPServerSegmentInterfaceIP 
#subnet1SegmentPool eg: 192.168.2.0/24
route add -net subnet2SegmentPool gw DHCPServerSegmentInterfaceIP
route -n #check the route rules.
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

step7. Check the route relay

ping -C 1 otherSubnetSegmentIP
  • 1
  • 1

Attantion:General DHCPServer’s gateway assign to the internel GatewayServer, so need to set the static route rules that DHCPServer can send the response to DHCPServerSubnetSegmentInterface then other subnetSegment will give the DHCPServer’s response.

转载:http://blog.csdn.net/jmilk/article/details/50173437

目录
相关文章
|
网络协议 Windows
路由交换基础——DHCP工作原理及DHCP Relay
路由交换基础——DHCP工作原理及DHCP Relay
340 0
路由交换基础——DHCP工作原理及DHCP Relay
|
开发工具
Linux_DHCP&DHCP Relay
目录 目录 DHCP DHCP Relay Setup DHCPServer Setup ClientPort DHCPDHCPRelay Setup DHCPRelay service DHCP DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议(计算机网络应用层协议 ),使用UDP协议工作。
1200 0
|
7月前
|
网络协议 Linux 应用服务中间件
2022红帽企业版网络配置--centos7配置DHCP DNS绑定域名 FTP HTTP(apache) nginx samba
2022红帽企业版网络配置--centos7配置DHCP DNS绑定域名 FTP HTTP(apache) nginx samba
149 0
|
2天前
|
域名解析 网络协议 Linux
TCP/IP协议及配置、IP地址、子网掩码、网关地址、DNS与DHCP介绍
TCP/IP协议及配置、IP地址、子网掩码、网关地址、DNS与DHCP介绍
|
3天前
|
网络协议
DHCP实验-动态主机配置协议
DHCP实验-动态主机配置协议
|
25天前
|
负载均衡 监控 网络虚拟化
华为配置DHCP Snooping防止DHCP Server仿冒者攻击示例
企业有三台FTP服务器Server1、Server2和Server3,且这三台服务器的硬件性能顺次降低,Server1性能是Server2的两倍、Server2性能是Server3的两倍。通过配置负载均衡,让这三台服务器联合对外提供FTP服务,且三台服务器承载业务的多少与服务器硬件性能的高低匹配。通过配置健康检测实时监控这三台服务器是否可达。
|
1月前
|
缓存 网络协议 网络虚拟化
网络技术基础(15)——DHCP简介与配置
【3月更文挑战第3天】刚加完班又去南京出差了,实在是太忙了。。。。网络基础笔记(加班了几天,中途耽搁了,预计推迟6天),这篇借鉴了之前师兄的笔记。
|
4月前
|
网络协议 网络架构
eNSP DHCP的配置
模拟华为设备中,路由器-交换机-PC三台设备,路由器作为DHCP服务器,PC作为DHCP客户端