1
gino86 2018-03-23 16:52:34 +08:00
查一下 iptables-extensions 的手册页,我记得里面好像有关于这方面的资料的,进去之后搜索 mss
|
2
lcdtyph 2018-03-23 17:05:11 +08:00 via iPhone
iptables -A $MY_CHAIN -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1400
|
3
tomychen 2018-03-23 17:22:26 +08:00
确定要动 mss 不是 mtu?
ip route add 0.0.0.0/0 dev eth0 advmss 1200 |
5
wsycqyz OP @tomychen 我改成 ip route change 0.0.0.0/dev eth0 advmss 1200,机器直接失去连接,重启才行。
|
6
wsycqyz OP @tomychen ip route change 0.0.0.0/ via xxx.xxx.xxx.xxx advmss 1200 无用,
wget 测试后,web 服务器端收到的 SYN 包 mss 还是 1460 |
7
goofool 2018-03-23 21:12:30 +08:00
-I OUTPUT -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1200
|
9
pheyx 2018-03-23 21:36:31 +08:00
@wsycqyz
看看这样行不行: iptables -t mangle -I POSTROUTING -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1200 放在 mangle 表中的 OUTPUT 链也是可以的,但 POSTROUTING 是包最后经过的一个链,所以会覆盖 OUTPUT 里的设置。 另外 OUTPUT 里的设置只针对本机发出的包,而 POSTROUTING 对本机发出的包和经过本机的包都有效。 建议看看这个图: https://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg |
10
extreme 2018-03-23 21:46:05 +08:00
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 2018-03-23 22:19:57 +08:00
不服气又试了一下...
是可以的 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 |