一个由于MTU值不合理造成的Frp内网穿透问题的解决

个人利用frp在单位的两个内网穿分别架设了一个http服务器,
两个内网分别有一条电信宽带,

两个frp的操作系统均为ubuntu,
连接同一个frps服务器

两个frpc的配置文件除端口以外完全正常,
其中一个内网frp穿透完全正常,
而另外一个http和SSH均有问题:

frpc文件如下

[web-bs]
type = http
local_ip = 127.0.0.1
local_port = 80
# use_compression = true
custom_domains = www.mydomain.com

[ssh-bs]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_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 success
2018/10/02 10:35:41 [I] [control.go:169] [3e5dcb9dd47ad723] [web] start proxy success
2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF
2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF
2018/10/02 10:40:22 [I] [control.go:308] [3e5dcb9dd47ad723] control writer is closing
2018/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, EOF
2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF
2018/10/02 10:40:22 [E] [control.go:152] [3e5dcb9dd47ad723] work connection closed, EOF
2018/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] success
2018/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 closing
2018/10/08 19:08:40 [I] [proxy.go:73] [c2f2312bf5ab125c] [web] proxy closing
2018/10/08 19:08:40 [I] [control.go:292] [c2f2312bf5ab125c] client exit success
2018/10/08 19:08:40 [W] [newhttp.go:209] http: proxy error: snappy: corrupt input
2018/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] success
2018/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 closing
2018/10/08 19:10:21 [I] [proxy.go:73] [c2f2312bf5ab125c] [web] proxy closing
2018/10/08 19:10:21 [I] [control.go:292] [c2f2312bf5ab125c] client exit success
2018/10/08 19:10:21 [W] [newhttp.go:209] http: proxy error: snappy: corrupt input
2018/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登录错误提示

root@FrpC-Server:/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.hxs.biz/html/20150518185006.html
并确定出合适的MTU值为1492

查看MTU值

root@FrpC-Server:/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 1492
至此故障解决

发表评论

电子邮件地址不会被公开。 必填项已用*标注