你的理解基本上正确,其实很简单的说法就是,linux收到包之后就查路由表,如果找到match的规则就做相应的操作,对需要送到本地的包也是有路由规则的,如下面的例子,列出了local table里边的路有规则
debian:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:8C:7C:3F
inet addr:10.1.24.210 Bcast:10.1.24.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe8c:7c3f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2397 errors:0 dropped:0 overruns:0 frame:0
TX packets:2165 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:208932 (204.0 KiB) TX bytes:370468 (361.7 KiB)
Interrupt:169 Base address:0x1400
eth1 Link encap:Ethernet HWaddr 00:0C:29:8C:7C:49
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe8c:7c49/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:468 (468.0 b)
Interrupt:177 Base address:0x1480
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
debian:~# ip route show table local
broadcast 192.168.0.255 dev eth1 proto kernel scope link src 192.168.0.1
broadcast 10.1.24.0 dev eth0 proto kernel scope link src 10.1.24.210
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
local 10.1.24.210 dev eth0 proto kernel scope host src 10.1.24.210
local 192.168.0.1 dev eth1 proto kernel scope host src 192.168.0.1
broadcast 192.168.0.0 dev eth1 proto kernel scope link src 192.168.0.1
broadcast 10.1.24.255 dev eth0 proto kernel scope link src 10.1.24.210
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
【 在 xly1030 (polestar) 的大作中提到: 】
: 现在有这样一个实验:两台linux主机,其中一台(M)上有两个网卡,两个IP分别为A:10.66.0.182 B:192.168.100.100,另一台(N)上只有一个网卡,IP为C:10.66.0.149。在N上增加这样一条路由:
: route add -net 192.168.100.0/24 gw 192.168.0.182
: 然后ping 192.168.100.100是可以ping通的,在M上并没有打开ip_forward。
: ...................