一個由於MTU值不合理造成的Frp內網穿透問題的解決
個人利用frp在單位的兩個內網穿架設了一個http伺服器,
兩個frp的作業系統均為ubuntu,
配置檔案除埠以外完全正常,
其中一個內網frp穿透完全正常,
而另外一個http和SSH均有問題:
frpc檔案如下
[web-bs]type = httplocal_ip = 127.0.0.1local_port = 80# use_compression = truecustom_domains = www.mydomain.com [ssh-bs]type = tcplocal_ip = 127.0.0.1local_port = 22remote_port = 10022
內網地址http://192.168.1.102/p.php,
外網地址http://www.mydomain.com/p.php
其中一臺出現一個奇怪的故障,內網訪問完全正常;
外網出錯,訪問部分html頁面會出錯(內網完全正常);
並且內網SSH連線正常,而經過Frp外網穿透的SSH連線斷開,原因不明
檢視frps.log
2018/10/02 10:35:41 [I] [control.go:246] [3e5dcb9dd47ad723] login to server success, get run id [3e5dcb9dd47ad723], server udp port [11111]2018/10/02 10:35:41 [I] [control.go:169] [3e5dcb9dd47ad723] [ssh] start proxy success2018/10/02 10:35:41 [I] [control.go:169] [3e5dcb9dd47ad723] [web] start proxy success2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF2018/10/02 10:40:22 [I] [control.go:308] [3e5dcb9dd47ad723] control writer is closing2018/10/02 10:40:22 [I] [control.go:407] [3e5dcb9dd47ad723] try to reconnect to server…2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF2018/10/02 10:40:22 [I] [control.go:246] [3e5dcb9dd47ad723] login to server success, get run id [3e5dcb9dd47ad723], server udp port [11111]
檢視frpc.log
2018/10/08 19:08:00 [I] [service.go:319] client login info: ip [222.77.157.34:51590] version [0.21.0] hostname [] os [linux] arch [amd64]2018/10/08 19:08:00 [I] [control.go:196] [c2f2312bf5ab125c] Replaced by client [c2f2312bf5ab125c]2018/10/08 19:08:01 [I] [proxy.go:273] [c2f2312bf5ab125c] [web] http proxy listen for host [bs.fdsyy.net] location []2018/10/08 19:08:01 [I] [control.go:335] [c2f2312bf5ab125c] new proxy [web-bs] success2018/10/08 19:08:18 [I] [proxy.go:87] [c2f2312bf5ab125c] [web] get a new work connection: [222.77.157.34:51590]2018/10/08 19:08:40 [I] [control.go:220] [c2f2312bf5ab125c] control writer is closing2018/10/08 19:08:40 [I] [proxy.go:73] [c2f2312bf5ab125c] [web] proxy closing2018/10/08 19:08:40 [I] [control.go:292] [c2f2312bf5ab125c] client exit success2018/10/08 19:08:40 [W] [newhttp.go:209] http: proxy error: snappy: corrupt input2018/10/08 19:08:41 [I] [service.go:319] client login info: ip [222.77.157.34:51594] version [0.21.0] hostname [] os [linux] arch [amd64]2018/10/08 19:08:41 [I] [control.go:196] [c2f2312bf5ab125c] Replaced by client [c2f2312bf5ab125c]2018/10/08 19:08:41 [I] [proxy.go:273] [c2f2312bf5ab125c] [web] http proxy listen for host [bs.fdsyy.net] location []2018/10/08 19:08:41 [I] [control.go:335] [c2f2312bf5ab125c] new proxy [web-bs] success2018/10/08 19:10:00 [I] [proxy.go:87] [c2f2312bf5ab125c] [web] get a new work connection: [222.77.157.34:51594]2018/10/08 19:10:21 [I] [control.go:220] [c2f2312bf5ab125c] control writer is closing2018/10/08 19:10:21 [I] [proxy.go:73] [c2f2312bf5ab125c] [web] proxy closing2018/10/08 19:10:21 [I] [control.go:292] [c2f2312bf5ab125c] client exit success2018/10/08 19:10:21 [W] [newhttp.go:209] http: proxy error: snappy: corrupt input2018/10/08 19:10:21 [I] [service.go:319] client login info: ip [222.77.157.34:51598] version [0.21.0] hostname [] os [linux] arch [amd64]
SSH登入錯誤提示
[email protected]:/home/frpc# vi2018/10/08 19:20:30 [ERR] yamux: keepalive failed: i/o deadline reached
2018/10/08 19:23:11 [ERR] yamux: keepalive failed: i/o deadline reached
確定frpc.ini和frps.ini配置檔案無誤,內網訪問完全正常;外網出錯;
而同樣的配置,另外一個光貓下的內網穿透正常;
兩個光貓下的網路MTU值不同,一個是1500,一個是1492;而Ubuntu預設的MTU值是1500;考慮可能是MTU設定不合理造成,
《修改MTU值優化網路》請參考:http://www.cainiao.blog/html/20150518185006.html
並確定出合適的MTU值為1492
檢視MTU值
[email protected]:/home/frpc# ifconfig
eth0 Link encap:Ethernet HWaddr 00:25:90:23:df:30
inet addr:10.10.10.142 Bcast:10.10.10.255 Mask:255.255.255.0
inet6 addr: fe80::225:90ff:fe23:df30/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:111294 errors:0 dropped:0 overruns:0 frame:0
TX packets:78378 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:38551275 (38.5 MB) TX bytes:7258246 (7.2 MB)
Interrupt:16 Memory:d0200000-d0220000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:10581 errors:0 dropped:0 overruns:0 frame:0
TX packets:10581 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:31291427 (31.2 MB) TX bytes:31291427 (31.2 MB)
修改本地MTU值
ifconfig eth0 mtu 1492 up
注意此命令重啟後實效,永久修改MTU值參考如下:
Edit the interfaces file to set the mtu when the interface comes up:
$ sudo vi /etc/network/interfaces
Edit the file so it includes the post-up line:
iface eth0 inet dhcp
. . .
post-up /sbin/ifconfig eth0 mtu 1500
至此故障解決