This topic created in 2999 days ago, the information mentioned may be changed or developed.
纯技术讨论,可能无实际用处。
一台 Linux 机器,wget 时,在目的机器上抓包,显示 SYN 的 tcp mss 为 1460,这是正常的行为。
Q: 我只有权限用这台 Linux 机器,在这台 Linux 机器上,我想把从这台 Linux 本地发出的 SYN 包的 tcp mss 改为 1200,可以吗?
搜索过,Linux 做为一个路由器,可以用 iptables 修改流过它的流量的 tcp mss,但是未搜索到如何修改本机发出的流量的 tcp mss。请指各位指教。
13 replies • 2018-03-24 15:01:54 +08:00
 |
|
1
gino86 Mar 23, 2018
查一下 iptables-extensions 的手册页,我记得里面好像有关于这方面的资料的,进去之后搜索 mss
|
 |
|
2
lcdtyph Mar 23, 2018 via iPhone
iptables -A $MY_CHAIN -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1400
|
 |
|
3
tomychen Mar 23, 2018
确定要动 mss 不是 mtu?
ip route add 0.0.0.0/0 dev eth0 advmss 1200
|
 |
|
4
wsycqyz Mar 23, 2018
@ lcdtyph 请问这个$MY_CHAIN 应该填成什么? OUTPUT? 试了一下好像不行
|
 |
|
5
wsycqyz Mar 23, 2018
@ tomychen 我改成 ip route change 0.0.0.0/dev eth0 advmss 1200,机器直接失去连接,重启才行。
|
 |
|
7
goofool Mar 23, 2018
-I OUTPUT -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1200
|
 |
|
8
lcdtyph Mar 23, 2018
@ wsycqyz #4 debian 9 亲测有效,请确认 OUTPUT 链中这条规则之前没有规则被成功匹配。
|
 |
|
10
extreme Mar 23, 2018
man iptables:
TCPMSS
This target allows to alter the MSS value of TCP SYN packets, to control the maximum size for that connection (usually limiting it to your outgoing interface's MTU minus 40). Of course, it can only be used in conjunction with -p tcp. It is only valid in the mangle table. This target is used to overcome criminally braindead ISPs or servers which block ICMP Fragmentation Needed packets. The symptoms of this problem are that everything works fine from your Linux firewall/router, but machines behind it can never exchange large packets: 1) Web browsers connect, then hang with no data received.
2)
Small mail works fine, but large emails hang.
3)
ssh works fine, but scp hangs after initial handshaking.
Workaround: activate this option and add a rule to your firewall configuration like: iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN \ -j TCPMSS --clamp-mss-to-pmtu --set-mss value Explicitly set MSS option to specified value. --clamp-mss-to-pmtu Automatically clamp MSS value to (path_MTU - 40). These options are mutually exclusive. TOS
This is used to set the 8-bit Type of Service field in the IP header. It is only valid in the mangle table. --set-tos tos You can use a numeric TOS values, or use iptables -j TOS -h to see the list of valid TOS names.
|
 |
|
12
tomychen Mar 23, 2018
不服气又试了一下... 是可以的 root@ubuntu-virtual-machine:~# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 192.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 root@ubuntu-virtual-machine:~# ip route change 0.0.0.0/0 via 192.168.1.1 dev eth0 advmss 1140 root@ubuntu-virtual-machine:~# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.1.1 0.0.0.0 UG 1180 0 0 eth0 192.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
只是在设置为 1140 的时候会 MSS 的值为 1180,但是服务器 tcpdump 得到的 mss 是 1140
|