DHCP
- 簡(jiǎn)單的來(lái)說(shuō),DHCP是一個(gè)局域網(wǎng)協(xié)議,使用UDP協(xié)議進(jìn)行工作瓣颅,它的作用就是動(dòng)態(tài)的分配IP地址,Gateway地址凳忙,DNS服務(wù)器地址等信息,一旦租約到期禽炬,那么路由器就會(huì)把當(dāng)前的這個(gè)ip分配給其他設(shè)備使用涧卵,所以,對(duì)于設(shè)備而言要定期請(qǐng)求DHCP Server來(lái)更新ip地址信息瞎抛,保證ip地址有效可用
DHCP租約到期艺演,設(shè)備不會(huì)自動(dòng)進(jìn)行續(xù)租而仍然使用舊的ip地址
- https://www.net.princeton.edu/android/android-stops-renewing-lease-keeps-using-IP-address-11236.html
DHCP租約到期,設(shè)備向DHCP Server發(fā)起請(qǐng)求桐臊,但是沒(méi)有收到Ack
- 遇到如上情況會(huì)導(dǎo)致ip無(wú)法更新,所以設(shè)備仍然會(huì)使用舊的ip晓殊,對(duì)于tcp連接來(lái)說(shuō)断凶,使用舊的過(guò)期ip就意味著連接不到遠(yuǎn)程服務(wù)器,從我們的日志信息中可以得知巫俺,當(dāng)TCP使用過(guò)期的ip去連接遠(yuǎn)程服務(wù)器的時(shí)候會(huì)報(bào)如下異常:java.net.NoRouteToHostException: No route to host认烁,意思是說(shuō)沒(méi)有可達(dá)Host的路由,確實(shí)是這樣的,設(shè)備連接無(wú)線網(wǎng)是連接到路由器上的却嗡,而路由器上分配給設(shè)備的ip已經(jīng)過(guò)期不可用舶沛,那么設(shè)備到路由器的鏈路是通的,但是路由器到遠(yuǎn)程主機(jī)的鏈路肯定是不通的窗价,所以會(huì)報(bào)如上錯(cuò)誤
- 正常情況下如庭,我們的Android設(shè)備在處于熄屏的狀態(tài)下,DHCP的租約是1個(gè)小時(shí)撼港,所以會(huì)每隔半小時(shí)就請(qǐng)求DHCP Server來(lái)更新ip地址:
Line 30221: 09-11 12:58:51.016 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 30227: 09-11 12:58:51.246 1835 3791 D DhcpClient: Received packet: 00:0a:f5:43:d8:7c ACK: your new IP /172.28.88.48, netmask /255.255.248.0, gateways [/172.28.88.254] DNS servers: /114.114.114.114 /172.28.1.28 /8.8.8.8 /172.28.1.26 , lease time 3600
Line 30228: 09-11 12:58:51.247 1835 3789 D DhcpClient: Renewed lease: IP address 172.28.88.48/21 Gateway 172.28.88.254 DNS servers: [ 114.114.114.114 172.28.1.28 8.8.8.8 172.28.1.26 ] Domains dw.gdbbk.com DHCP server /1.1.1.1 Vendor info ?????? lease 3600 seconds
Line 30228: 09-11 12:58:51.247 1835 3789 D DhcpClient: Renewed lease: IP address 172.28.88.48/21 Gateway 172.28.88.254 DNS servers: [ 114.114.114.114 172.28.1.28 8.8.8.8 172.28.1.26 ] Domains dw.gdbbk.com DHCP server /1.1.1.1 Vendor info ?????? lease 3600 seconds
Line 30243: 09-11 12:58:51.252 1835 3789 D DhcpClient: Scheduling renewal in 1799s
Line 30244: 09-11 12:58:51.253 1835 3789 D DhcpClient: Scheduling rebind in 3149s
Line 30245: 09-11 12:58:51.253 1835 3789 D DhcpClient: Scheduling expiry in 3599s
Line 30718: 09-11 13:28:51.280 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 30718: 09-11 13:28:51.280 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 30722: 09-11 13:28:51.306 1835 3791 D DhcpClient: Received packet: 00:0a:f5:43:d8:7c ACK: your new IP /172.28.88.48, netmask /255.255.248.0, gateways [/172.28.88.254] DNS servers: /114.114.114.114 /172.28.1.28 /8.8.8.8 /172.28.1.26 , lease time 3600
Line 30723: 09-11 13:28:51.307 1835 3789 D DhcpClient: Renewed lease: IP address 172.28.88.48/21 Gateway 172.28.88.254 DNS servers: [ 114.114.114.114 172.28.1.28 8.8.8.8 172.28.1.26 ] Domains dw.gdbbk.com DHCP server /1.1.1.1 Vendor info ?????? lease 3600 seconds
Line 30723: 09-11 13:28:51.307 1835 3789 D DhcpClient: Renewed lease: IP address 172.28.88.48/21 Gateway 172.28.88.254 DNS servers: [ 114.114.114.114 172.28.1.28 8.8.8.8 172.28.1.26 ] Domains dw.gdbbk.com DHCP server /1.1.1.1 Vendor info ?????? lease 3600 seconds
Line 30747: 09-11 13:28:51.316 1835 3789 D DhcpClient: Scheduling renewal in 1799s
Line 30748: 09-11 13:28:51.316 1835 3789 D DhcpClient: Scheduling rebind in 3149s
Line 30749: 09-11 13:28:51.316 1835 3789 D DhcpClient: Scheduling expiry in 3599s
Line 31114: 09-11 13:58:53.153 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 31114: 09-11 13:58:53.153 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 31120: 09-11 13:58:53.220 1835 3791 D DhcpClient: Received packet: 00:0a:f5:43:d8:7c ACK: your new IP /172.28.88.48, netmask /255.255.248.0, gateways [/172.28.88.254] DNS servers: /114.114.114.114 /172.28.1.28 /8.8.8.8 /172.28.1.26 , lease time 3600
Line 31121: 09-11 13:58:53.221 1835 3789 D DhcpClient: Renewed lease: IP address 172.28.88.48/21 Gateway 172.28.88.254 DNS servers: [ 114.114.114.114 172.28.1.28 8.8.8.8 172.28.1.26 ] Domains dw.gdbbk.com DHCP server /1.1.1.1 Vendor info ?????? lease 3600 seconds
Line 31121: 09-11 13:58:53.221 1835 3789 D DhcpClient: Renewed lease: IP address 172.28.88.48/21 Gateway 172.28.88.254 DNS servers: [ 114.114.114.114 172.28.1.28 8.8.8.8 172.28.1.26 ] Domains dw.gdbbk.com DHCP server /1.1.1.1 Vendor info ?????? lease 3600 seconds
Line 31133: 09-11 13:58:53.226 1835 3789 D DhcpClient: Scheduling renewal in 1799s
Line 31134: 09-11 13:58:53.226 1835 3789 D DhcpClient: Scheduling rebind in 3149s
Line 31135: 09-11 13:58:53.226 1835 3789 D DhcpClient: Scheduling expiry in 3599s
以上是發(fā)起請(qǐng)求后有正常收到Ack的情況坪它,但是接下來(lái)設(shè)備發(fā)起了請(qǐng)求并沒(méi)有收到Ack帝牡,所以導(dǎo)致設(shè)備一直不斷的去發(fā)起DHCP請(qǐng)求往毡,而且此時(shí)設(shè)備并沒(méi)有網(wǎng)絡(luò)切換廣播,并且設(shè)備本地判斷網(wǎng)絡(luò)是正晨t?捎玫模蚴窃O(shè)備到路由器的網(wǎng)絡(luò)是通的罩息,只是路由器到遠(yuǎn)程服務(wù)器的鏈路是不通的:
33540: 09-11 14:28:54.007 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33540: 09-11 14:28:54.007 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33557: 09-11 14:28:59.012 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33557: 09-11 14:28:59.012 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33585: 09-11 14:29:04.021 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33585: 09-11 14:29:04.021 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33701: 09-11 14:29:12.088 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33701: 09-11 14:29:12.088 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33724: 09-11 14:29:28.065 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33724: 09-11 14:29:28.065 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33779: 09-11 14:30:03.317 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33779: 09-11 14:30:03.317 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33815: 09-11 14:31:13.838 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 33815: 09-11 14:31:13.838 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 51658: 09-11 14:33:33.786 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 51658: 09-11 14:33:33.786 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 53369: 09-11 14:35:32.229 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 53369: 09-11 14:35:32.229 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 53714: 09-11 14:37:46.146 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 53714: 09-11 14:37:46.146 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 55611: 09-11 14:40:02.569 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 55611: 09-11 14:40:02.569 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 57692: 09-11 14:42:01.271 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
Line 57692: 09-11 14:42:01.271 1835 3789 D DhcpClient: Unicasting DHCPREQUEST ciaddr=172.28.88.48 request=0.0.0.0 serverid=null to /1.1.1.1:67
在這段時(shí)間內(nèi),TCP連接是一直報(bào)java.net.NoRouteToHostException: No route to host異常扣汪,如果TCP當(dāng)前正處于連接中断楷,那么DHCP的更新可能會(huì)導(dǎo)致TCP斷線,等到后面設(shè)備發(fā)起的DHCP請(qǐng)求收到Ack之后崭别,TCP連接立刻恢復(fù)正常,并且此時(shí)收到了網(wǎng)絡(luò)切換廣播茅主,針對(duì)以上問(wèn)題,如何恢復(fù)呢诀姚?搜索網(wǎng)上資料是說(shuō)應(yīng)用程序每次重新建立一條新的TCP的時(shí)候會(huì)觸發(fā)設(shè)備請(qǐng)求DHCP Server响牛,但是從我們的log查看發(fā)現(xiàn)并沒(méi)有,請(qǐng)求DHCP Server沒(méi)有Ack后設(shè)備會(huì)間隔重試赫段,當(dāng)設(shè)備被觸發(fā)亮屏后呀打,網(wǎng)絡(luò)馬上恢復(fù)正常,DHCP請(qǐng)求也收到Ack糯笙,同時(shí)也收到網(wǎng)絡(luò)切換廣播