- 论坛徽章:
- 12
|
本帖最后由 phanx 于 2014-08-20 23:56 编辑
回复 11# jiufei19
是的,你是正确的。 我做了个TRACE
[root@testhost ~]# modprobe ipt_LOG
[root@testhost ~]# iptables -t raw -A PREROUTING --dst 10.0.0.222 -j TRACE
[root@testhost ~]# iptables -L -v -n -t raw
Chain PREROUTING (policy ACCEPT 6324 packets, 1112K bytes)
pkts bytes target prot opt in out source destination
0 0 TRACE all -- * * 0.0.0.0/0 10.0.0.222
Chain OUTPUT (policy ACCEPT 395 packets, 104K bytes)
pkts bytes target prot opt in out source destination
22 5026 TRACE tcp -- * * 0.0.0.0/0 10.0.0.222 tcp spt:22
下面是TRACE结果
[root@testhost ~]#cat /var/log/message
testhost kernel: TRACE: raw:OUTPUT:rule:2 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0
testhost kernel: TRACE: raw:OUTPUT:policy:3 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0
testhost kernel: TRACE: mangle:OUTPUT:rule:1 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0
testhost kernel: output IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 WINDOW=14600 RES=0x00 ACK SYN URGP=0
testhost kernel: TRACE: mangle:OUTPUT:rule:3 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0
testhost kernel: TRACE: mangle:OUTPUT:rule:4 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0 MARK=0x64
testhost kernel: TRACE: mangle:OUTPUT:policy:5 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0 MARK=0x64
testhost kernel: TRACE: filter:OUTPUT:policy:1 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0 MARK=0x64
testhost kernel: TRACE: mangle: POSTROUTING:policy:1 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=52 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269519 ACK=1766750704 WINDOW=14600 RES=0x00 ACK SYN URGP=0 OPT (020405B40101040201030307) UID=0 GID=0 MARK=0x64
testhost kernel: TRACE: raw:OUTPUT:rule:2 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=35912 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269520 ACK=1766750755 WINDOW=115 RES=0x00 ACK URGP=0
testhost kernel: TRACE: raw:OUTPUT:policy:3 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=35912 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269520 ACK=1766750755 WINDOW=115 RES=0x00 ACK URGP=0
testhost kernel: TRACE: mangle:OUTPUT:rule:1 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=35912 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269520 ACK=1766750755 WINDOW=115 RES=0x00 ACK URGP=0
testhost kernel: output IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=35912 DF PROTO=TCP SPT=22 DPT=51680 WINDOW=115 RES=0x00 ACK URGP=0
testhost kernel: TRACE: mangle:OUTPUT:rule:3 IN= OUT=em1 SRC=192.168.1.111 DST=10.0.0.222 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=35912 DF PROTO=TCP SPT=22 DPT=51680 SEQ=669269520 ACK=1766750755 WINDOW=115 RES=0x00 ACK URGP=0
看到的情况也跟你的得出的结论是一致的。
本机主动发出的包,只会从OUTPUT Chain出去。由于OUTPUT在路由之后,所以就算设置了MARK也不能再匹配路由规则了。如果是转发报文,那么在IN的时候可以在PREROUTING上set mark。这个时候应该就可以匹配到对应的路由规则了。
在default 路由表没有到10.0.0.222的路由,只有table 100 有到10.0.0.222的路由的时候,根本不会有任何输出,直接是路由不可达,证明了确实是先选路由。 |
|