我有两个设置,我想在其中更改流经系统的数据包的 MSS。在第一个设置中,我将 enp2s0 和 enp3s0 设置为桥接。有没有办法让 iptables 在将入站数据包传回之前修改其 MSS?
[root@localhost network-scripts]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
link/ether 00:60:e0:6f:8c:62 brd ff:ff:ff:ff:ff:ff
3: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP qlen 1000
link/ether 00:60:e0:6f:8c:63 brd ff:ff:ff:ff:ff:ff
4: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:60:e0:6f:8c:61 brd ff:ff:ff:ff:ff:ff
inet 192.168.5.248/24 brd 192.168.5.255 scope global enp0s31f6
valid_lft forever preferred_lft forever
inet6 fe80::1842:306e:fb55:fe3/64 scope link
valid_lft forever preferred_lft forever
5: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP qlen 1000
link/ether 00:60:e0:6f:8c:64 brd ff:ff:ff:ff:ff:ff
7: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 00:60:e0:6f:8c:63 brd ff:ff:ff:ff:ff:ff
inet6 fe80::260:e0ff:fe6f:8c63/64 scope link
valid_lft forever preferred_lft forever
[root@localhost network-scripts]#
在第二种情况下,我将所有流量设置为转到虚构的 tun0,它将流量发送到队列 0,在该队列中类似 snort 的软件会分析数据包。
root@pink:~/blue# iptables-save
# Generated by iptables-save v1.6.0 on Sun Jan 14 13:22:07 2018
*raw
:PREROUTING ACCEPT [84:6848]
:OUTPUT ACCEPT [21:2348]
-A PREROUTING -i tun0 -j NFQUEUE --queue-num 0
COMMIT
# Completed on Sun Jan 14 13:22:07 2018
# Generated by iptables-save v1.6.0 on Sun Jan 14 13:22:07 2018
*filter
:INPUT ACCEPT [110838:165446612]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [87556:6202390]
COMMIT
# Completed on Sun Jan 14 13:22:07 2018
root@pink:~/blue#
我试过这个https://www.frozentux.net/iptables-tutorial/chunkyhtml/x4721.html但似乎没有作用。
答案1
您可以使用 TCPMSS iptables 目标来修改 TCP MSS 值,即执行 MSS 钳制。
要强制特定的 MSS(此处:800),使用:
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 800
请注意,如果您使用 conntrack,这会变得有点棘手。此规则必须前conntrack 规则。否则,它只适用于 SYN 数据包,而不适用于 SYN ACK,后者在到达 TCPMSS 规则之前会被 conntrack 接受。
还请注意,MSS 夹紧是一种黑客技术,仅当您的最终用户应用程序损坏时才需要。