読者です 読者をやめる 読者になる 読者になる

apt-get が途中で0% [Waiting for headers] [Waiting for headers] から動かなくなる。git clone もうまく行かない

Ubuntu 16.04 git apt network

apt-get update が途中で0% [Waiting for headers] [Waiting for headers] から動かなくなる。

user@server:$ sudo apt-get update
Hit:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
Ign:2 http://dl.google.com/linux/chrome/deb stable InRelease                   
Hit:3 http://download.virtualbox.org/virtualbox/debian raring InRelease        
Ign:4 http://archive.ubuntulinux.jp/ubuntu xenial InRelease                    
Hit:5 http://archive.ubuntulinux.jp/ubuntu xenial Release                      
Hit:7 http://dl.google.com/linux/chrome/deb stable Release                     
Ign:9 http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist InRelease   
Hit:10 http://ppa.launchpad.net/cwchien/gradle/ubuntu xenial InRelease         
Hit:11 http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist Release    
Hit:13 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease       
Ign:14 https://dl.bintray.com/sbt/debian  InRelease                       
Get:15 https://dl.bintray.com/sbt/debian  Release [814 B]
Hit:15 https://dl.bintray.com/sbt/debian  Release                       
0% [Waiting for headers] [Waiting for headers]            

止まる箇所はいろいろで、 git clone も必ず失敗する。 何か大きすぎるファイルでもあったかなと思うけど これも止まるパーセンテージが毎回違う

user@server:~$ git clone git@gitserver/repos.git
Cloning into 'repos'...
remote: Counting objects: 1242, done.
remote: Compressing objects:  26% (159/611)  

しかも回数試すと落とせている量がだんだん少なくなって不安

user@server:~$ git clone git@gitserver/repos.git
Cloning into 'repos'...
remote: Counting objects: 1242, done.
remote: Compressing objects:  16% (98/611)   
^Cfatal: The remote end hung up unexpectedly

user@server:~$ git clone git@gitserver/repos.git
Cloning into 'repos'...
remote: Counting objects: 1242, done.
remote: Compressing objects:  13% (80/611)   
^Cfatal: The remote end hung up unexpectedly

user@server:~$ git clone git@gitserver/repos.git
Cloning into 'repos'...
remote: Counting objects: 1242, done.
remote: Compressing objects:  19% (117/611)   
^Cfatal: The remote end hung up unexpectedly

毎回必ず減るわけでもなかった

原因

変えてみて治ったからわかったのだけど、
MTU の設定がお気に召さなかったよう。
今 1500 になっている

user@server:~$ ifconfig
~~~

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ethnum    Link encap:Ethernet  HWaddr nn:nn:nn:nn:nn:nn  
          inet addr:nn.nn.nn.nn  Bcast:nn.nn.nn.nn  Mask:nn.nn.nn.nn
          inet6 addr: nnnn.nnnn.nnn.nnnn/nn Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9272391 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11482380 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4768499875 (4.7 GB)  TX bytes:8317645986 (8.3 GB)
          Interrupt:18 Memory:f71c0000-f71e0000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
~~~

解決方法

mtu を適切に設定

user@server:~$ sudo ifconfig ethnum mtu 1468

最適な MTU の確認方法

パケットのサイズを指定しながら ping を打ってみて、繋がる最大値が最適な値です。
下での確認内容

  1. 1500 で送ってみて、帰ってこないのでNG (1500は今の値なので当然つながらない)
  2. 1400 で OK
  3. 1450 で OK
  4. 1475 で NG
  5. 1462 で OK
  6. 1468 で OK
  7. 1470 で NG
  8. 1469 で NG
  9. 1468 で OK

なので、1468 で設定。
確認がややこしければ1450 とかにしてみて繋がるならそのままでもokです。
効率は悪くなるけど、まずは繋がるんだから . .

user@server:~$ ping -c 1 -s 1500 example.com
PING example.com (93.184.216.34) 1500(1528) bytes of data.

^C
--- example.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@server:~$ ping -c 1 -s 1400 example.com
PING example.com (93.184.216.34) 1400(1428) bytes of data.
1408 bytes from 93.184.216.34: icmp_seq=1 ttl=51 time=129 ms

--- example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 129.984/129.984/129.984/0.000 ms
user@server:~$ ping -c 1 -s 1450 example.com
PING example.com (93.184.216.34) 1450(1478) bytes of data.
1458 bytes from 93.184.216.34: icmp_seq=1 ttl=51 time=129 ms

--- example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 129.737/129.737/129.737/0.000 ms
user@server:~$ ping -c 1 -s 1475 example.com
PING example.com (93.184.216.34) 1475(1503) bytes of data.
^C
--- example.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@server:~$ ping -c 1 -s 1462 example.com
PING example.com (93.184.216.34) 1462(1490) bytes of data.
1470 bytes from 93.184.216.34: icmp_seq=1 ttl=51 time=129 ms

--- example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 129.576/129.576/129.576/0.000 ms
user@server:~$ ping -c 1 -s 1468 example.com
PING example.com (93.184.216.34) 1468(1496) bytes of data.
1476 bytes from 93.184.216.34: icmp_seq=1 ttl=51 time=130 ms

--- example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 130.739/130.739/130.739/0.000 ms
user@server:~$ ping -c 1 -s 1470 example.com
PING example.com (93.184.216.34) 1470(1498) bytes of data.
^C
--- example.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@server:~$ ping -c 1 -s 1469 example.com
PING example.com (93.184.216.34) 1469(1497) bytes of data.

^C
--- example.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@server:~$ ping -c 1 -s 1468 example.com
PING example.com (93.184.216.34) 1468(1496) bytes of data.
1476 bytes from 93.184.216.34: icmp_seq=1 ttl=51 time=130 ms

--- example.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 130.318/130.318/130.318/0.000 ms
user@server:~$