我有一个 CentOS 7 系统,它有三个接口。我最近将其中一个接口转换为使用 VLAN。该系统充当各种网络之间的防火墙和路由器。除了一件事外,一切似乎都按预期运行。我无法从 VLAN 上的任何主机连接到 CentOS 系统或从 VLAN 上的任何主机连接到 CentOS 系统。
例如,如果我从 192.168.32.95(VLAN 32 上的主机)通过 ssh 连接到 192.168.32.1(CentOS 主机上的 VLAN 32 接口),我可以使用 tcpdump 看到数据包到达 enp3s0 接口,并带有 vlan 32 标签。iptables INPUT 链记录并接受该数据包。之后,数据包消失了。没有发送 SYN-ACK,也没有发送 RST。
类似地,对于从 192.168.32.1 到 192.168.32.3 的 NTP,防火墙记录并接受传出的 NTP 数据包,但 tcpdump 在 enp3s0(即 enp3s0.32)上没有看到任何数据包
来自 VLAN 32 的 ping 操作有效...我可以从 VLAN 32 ping CentOS 主机并得到答复。
CentOS 系统正在 VLAN 和非 VLAN 接口的所有组合之间转发数据包。
有什么想法可以解释这些连接问题,或者有没有什么方法可以进一步追踪正在发生的事情?
# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether c0:25:e9:0e:cb:a1 brd ff:ff:ff:ff:ff:ff
inet 10.20.30.177/28 brd 10.20.30.191 scope global enp1s0
valid_lft forever preferred_lft forever
3: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 84:16:f9:05:3a:fb brd ff:ff:ff:ff:ff:ff
inet 192.168.16.1/24 brd 192.168.16.255 scope global enp2s0
valid_lft forever preferred_lft forever
4: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 6c:f0:49:42:5b:fa brd ff:ff:ff:ff:ff:ff
5: enp3s0.32@enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 6c:f0:49:42:5b:fa brd ff:ff:ff:ff:ff:ff
inet 192.168.32.1/24 brd 192.168.32.255 scope global enp3s0.32
valid_lft forever preferred_lft forever
6: enp3s0.50@enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 6c:f0:49:42:5b:fa brd ff:ff:ff:ff:ff:ff
inet 192.168.50.1/24 brd 192.168.50.255 scope global enp3s0.50
valid_lft forever preferred_lft forever
这是 INPUT 链,我在最开始的地方放置了日志记录和 ACCEPT 规则。
# iptables -t filter -S INPUT
-P INPUT DROP
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.32.95/32 -d 192.168.32.1/32 -p tcp -m tcp --dport 22 -j LOG --log-prefix "TEST IN: "
-A INPUT -s 192.168.32.95/32 -d 192.168.32.1/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -m state --state INVALID -j INVALID
-A INPUT -m state --state UNTRACKED -j UNTRACKED
-A INPUT -i enp1s0 -j INPUT-EXT
-A INPUT -i enp2s0 -j INPUT-MID
-A INPUT -i enp3s0.32 -j INPUT-V32
-A INPUT -i enp3s0.50 -j INPUT-V50
-A INPUT -j LOG --log-prefix "DROP EOC INPUT: " --log-tcp-options --log-ip-options
-A INPUT -j DROP
防火墙记录 SYN 数据包。
Jul 4 14:21:49 outside kernel: [112380.489332] TEST IN: IN=enp3s0.32 OUT= MAC=6c:f0:49:42:5b:fa:52:54:00:35:f4:e4:08:00:45:00:00:3c SRC=192.168.32.95 DST=192.168.32.1 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=17731 DF PROTO=TCP SPT=51926 DPT=22 WINDOW=29200 RES=0x00 SYN URGP=0
tcpdump 的输出显示 SYN 数据包的多个副本已到达。
# tcpdump -e -nn -i enp3s0 host 192.168.32.95 and host 192.168.32.1
14:21:49.516122 52:54:00:35:f4:e4 > 6c:f0:49:42:5b:fa, ethertype 802.1Q (0x8100), length 78: vlan 32, p 0, ethertype IPv4, 192.168.32.95.51926 > 192.168.32.1.22: Flags [S], seq 3631520692, win 29200, options [mss 1460,sackOK,TS val 69303507 ecr 0,nop,wscale 7], length 0
14:21:50.529043 52:54:00:35:f4:e4 > 6c:f0:49:42:5b:fa, ethertype 802.1Q (0x8100), length 78: vlan 32, p 0, ethertype IPv4, 192.168.32.95.51926 > 192.168.32.1.22: Flags [S], seq 3631520692, win 29200, options [mss 1460,sackOK,TS val 69303760 ecr 0,nop,wscale 7], length 0
14:21:52.543926 52:54:00:35:f4:e4 > 6c:f0:49:42:5b:fa, ethertype 802.1Q (0x8100), length 78: vlan 32, p 0, ethertype IPv4, 192.168.32.95.51926 > 192.168.32.1.22: Flags [S], seq 3631520692, win 29200, options [mss 1460,sackOK,TS val 69304264 ecr 0,nop,wscale 7], length 0
14:21:56.607938 52:54:00:35:f4:e4 > 6c:f0:49:42:5b:fa, ethertype 802.1Q (0x8100), length 78: vlan 32, p 0, ethertype IPv4, 192.168.32.95.51926 > 192.168.32.1.22: Flags [S], seq 3631520692, win 29200, options [mss 1460,sackOK,TS val 69305280 ecr 0,nop,wscale 7], length 0
14:22:04.799936 52:54:00:35:f4:e4 > 6c:f0:49:42:5b:fa, ethertype 802.1Q (0x8100), length 78: vlan 32, p 0, ethertype IPv4, 192.168.32.95.51926 > 192.168.32.1.22: Flags [S], seq 3631520692, win 29200, options [mss 1460,sackOK,TS val 69307328 ecr 0,nop,wscale 7], length 0
其他所需信息:
# ip route
default via 50.196.138.190 dev enp1s0
10.20.30.176/28 dev enp1s0 proto kernel scope link src 10.20.30.177
192.168.16.0/24 dev enp2s0 proto kernel scope link src 192.168.16.1
192.168.32.0/24 dev enp3s0.32 proto kernel scope link src 192.168.32.1
192.168.50.0/24 dev enp3s0.50 proto kernel scope link src 192.168.50.1
# ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
# ip route show table local
broadcast 10.20.30.176 dev enp1s0 proto kernel scope link src 10.20.30.177
local 10.20.30.177 dev enp1s0 proto kernel scope host src 10.20.30.177
broadcast 10.20.30.191 dev enp1s0 proto kernel scope link src 10.20.30.177
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
broadcast 192.168.16.0 dev enp2s0 proto kernel scope link src 192.168.16.1
local 192.168.16.1 dev enp2s0 proto kernel scope host src 192.168.16.1
broadcast 192.168.16.255 dev enp2s0 proto kernel scope link src 192.168.16.1
broadcast 192.168.32.0 dev enp3s0.32 proto kernel scope link src 192.168.32.1
local 192.168.32.1 dev enp3s0.32 proto kernel scope host src 192.168.32.1
broadcast 192.168.32.255 dev enp3s0.32 proto kernel scope link src 192.168.32.1
broadcast 192.168.50.0 dev enp3s0.50 proto kernel scope link src 192.168.50.1
local 192.168.50.1 dev enp3s0.50 proto kernel scope host src 192.168.50.1
broadcast 192.168.50.255 dev enp3s0.50 proto kernel scope link src 192.168.50.1
我已经在 OUTPUT 链中添加了特定的日志记录和 ACCEPT 规则,但是没有任何内容被记录下来。
# iptables -S OUTPUT
-P OUTPUT DROP
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -s 192.168.32.1/32 -d 192.168.32.95/32 -p tcp -m tcp --sport 22 -j LOG --log-prefix "TEST OUT: "
-A OUTPUT -s 192.168.32.1/32 -d 192.168.32.95/32 -p tcp -m tcp --sport 22 -j ACCEPT
-A OUTPUT -m state --state INVALID -j INVALID
-A OUTPUT -m state --state UNTRACKED -j UNTRACKED
-A OUTPUT -o enp1s0 -j OUTPUT-EXT
-A OUTPUT -o enp2s0 -j OUTPUT-MID
-A OUTPUT -o enp3s0.32 -j OUTPUT-V32
-A OUTPUT -o enp3s0.50 -j OUTPUT-V50
-A OUTPUT -j LOG --log-prefix "DROP EOC OUTPUT: " --log-tcp-options --log-ip-options
-A OUTPUT -j DROP
# ss -atn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:199 *:*
LISTEN 0 128 *:22 *:*
SYN-RECV 0 0 192.168.32.1%if378475780:22 192.168.32.95:36778
LISTEN 0 100 127.0.0.1:25 *:*
ESTAB 0 292 192.168.16.1:22 192.168.16.61:49618
# cat /etc/sysconfig/network-scripts/ifcfg-enp3s0.32
DEVICE=enp3s0.32
TYPE=Ethernet
ONBOOT=yes
VLAN=yes
BOOTPROTO=static
IPADDR=192.168.32.1
NETMASK=255.255.255.0
IPV6INIT=no
# cat /etc/sysconfig/network-scripts/ifcfg-enp3s0
DEVICE=enp3s0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPV6INIT=no
以下是三次尝试 ssh 进入此主机的情况。以下每个列表都是在前一次 ssh 因连接超时而退出后以及前一次 SYN-RECV 消失后。我从输出中删除了 LISTEN 和 ESTAB 行,因为它们与之前的输出基本相同。此外,SYN-RECV 行在进程列中为空白。
# ss -atnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
SYN-RECV 0 0 192.168.32.1%if-8096:22 192.168.32.95:47290
# ss -atnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
SYN-RECV 0 0 192.168.32.1%if378479604:22 192.168.32.95:47440
# ss -atnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
SYN-RECV 0 0 192.168.32.1%if378479648:22 192.168.32.95:47580
另一个实验是,我尝试启动多个 ssh 连接,间隔 1 秒:
for x in 1 2 3 4 5 6 7 8 9 10 ; do ssh -n 192.168.32.1 date & sleep 1; done
在所有 ssh 进程运行后,ss 输出如下所示。tcpdump 没有报告 SYN-ACK 数据包。ss 输出保持不变,直到连接超时。
# ss -atn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
SYN-RECV 0 0 192.168.32.1%if378480635:22 192.168.32.95:50492
SYN-RECV 0 0 192.168.32.1%if378480636:22 192.168.32.95:50502
SYN-RECV 0 0 192.168.32.1%if378480636:22 192.168.32.95:50498
SYN-RECV 0 0 192.168.32.1%if378480635:22 192.168.32.95:50494
SYN-RECV 0 0 192.168.32.1:22 192.168.32.95:50488
SYN-RECV 0 0 192.168.32.1%if378480634:22 192.168.32.95:50486
SYN-RECV 0 0 192.168.32.1%if378480634:22 192.168.32.95:50490
SYN-RECV 0 0 192.168.32.1:22 192.168.32.95:50504
SYN-RECV 0 0 192.168.32.1%if378480636:22 192.168.32.95:50496
SYN-RECV 0 0 192.168.32.1%if378480636:22 192.168.32.95:50500
系统设置是相当标准的配置。在最近的更改之前,enp3s0 接口是 192.168.32.0/24 网络。唯一真正的变化是 sysconfig 下的 ifcfg-enp3s0* 文件,以及更新防火墙规则。大多数主机都从旧子网移动到 vlan 32,没有改变。