DHCP租约到期自动续租问题导致TCP连接异常

DHCP

  • 简单的来说,DHCP是一个局域网协议,使用UDP协议进行工作,它的作用就是动态的分配IP地址,Gateway地址,DNS服务器地址等信息,一旦租约到期,那么路由器就会把当前的这个ip分配给其他设备使用,所以,对于设备而言要定期请求DHCP Server来更新ip地址信息,保证ip地址有效可用

DHCP租约到期,设备不会自动进行续租而仍然使用旧的ip地址

DHCP租约到期,设备向DHCP Server发起请求,但是没有收到Ack

  • 遇到如上情况会导致ip无法更新,所以设备仍然会使用旧的ip,对于tcp连接来说,使用旧的过期ip就意味着连接不到远程服务器,从我们的日志信息中可以得知,当TCP使用过期的ip去连接远程服务器的时候会报如下异常:java.net.NoRouteToHostException: No route to host,意思是说没有可达Host的路由,确实是这样的,设备连接无线网是连接到路由器上的,而路由器上分配给设备的ip已经过期不可用,那么设备到路由器的链路是通的,但是路由器到远程主机的链路肯定是不通的,所以会报如上错误
  • 正常情况下,我们的Android设备在处于熄屏的状态下,DHCP的租约是1个小时,所以会每隔半小时就请求DHCP Server来更新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

以上是发起请求后有正常收到Ack的情况,但是接下来设备发起了请求并没有收到Ack,所以导致设备一直不断的去发起DHCP请求,而且此时设备并没有网络切换广播,并且设备本地判断网络是正常可用的,原因是设备到路由器的网络是通的,只是路由器到远程服务器的链路是不通的:

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

在这段时间内,TCP连接是一直报java.net.NoRouteToHostException: No route to host异常,如果TCP当前正处于连接中,那么DHCP的更新可能会导致TCP断线,等到后面设备发起的DHCP请求收到Ack之后,TCP连接立刻恢复正常,并且此时收到了网络切换广播,针对以上问题,如何恢复呢?搜索网上资料是说应用程序每次重新建立一条新的TCP的时候会触发设备请求DHCP Server,但是从我们的log查看发现并没有,请求DHCP Server没有Ack后设备会间隔重试,当设备被触发亮屏后,网络马上恢复正常,DHCP请求也收到Ack,同时也收到网络切换广播

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,332评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,508评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,812评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,607评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,728评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,919评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,071评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,802评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,256评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,576评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,712评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,389评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,032评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,798评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,026评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,473评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,606评论 2 350

推荐阅读更多精彩内容