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是用來作「雙機熱備」的。web

DHCP Relay

DHCP Relay(DHCPR):DHCP中繼服務,也叫作DHCP中繼代理能夠實如今不一樣子網和物理網段之間處理和轉發dhcp信息的功能。若是DHCP客戶機與DHCP服務器在同一個物理網段,則客戶機能夠正確地得到動態分配的ip地址。若是不在同一個物理網段,則須要DHCP Relay Agent(中繼代理)。用DHCP Relay代理能夠去掉在每一個物理的網段都要有DHCP服務器的必要,它能夠傳遞消息到不在同一個物理子網的DHCP服務器,也能夠將服務器的消息傳回給不在同一個物理子網的DHCP客戶機。sql

Setup DHCPServer

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

yum install -y dhcpd

step2. Service config file (DHCPServer use static IP)服務器

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

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
}

step3. Start DHCP serverdom

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

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。svg

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:dchrelayui

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.confspa

net.ipv4.ip_forward = 1

Load sysctl configuration計算機網絡

sysctl -p

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

INTERFACES="eth0 eth1 eth2" #Relay interfacee
DHCPSERVERS="DHCPServerIP"

step4. Start dhcprelay service

service dhcrelay start

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.

step7. Check the route relay

ping -C 1 otherSubnetSegmentIP

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.

相關文章
相關標籤/搜索