如何設定多個網路介面在相同網段

例如在3個網路介面設定不一樣的IP(同一個網段)
192.168.0.100 192.168.0.101 192.168.0.102
同一個網段的其他電腦 192.168.0.199 ping這三個介面都會被回應
但真正回應的介面是在路由表的第一個介面(可由arp -n 得知)
而且每次重開機會亂跳

以前只會這樣設

/etc/sysctl.conf
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2

net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce=2

如此只有路由表上第一個網路介面的IP被回應,其他兩個無回應(每次開機還是會亂跳)

目前找到的解決方法[註1]

arp_filter - BOOLEAN
 1 - Allows you to have multiple network interfaces on the same
 subnet, and have the ARPs for each interface be answered
 based on whether or not the kernel would route a packet from
 the ARP'd IP out that interface (therefore you must use source
 based routing for this to work). In other words it allows control
 of which cards (usually 1) will respond to an arp request.
0 - (default) The kernel can respond to arp requests with addresses
 from other interfaces. This may seem wrong but it usually makes
 sense, because it increases the chance of successful communication.
 IP addresses are owned by the complete host on Linux, not by
 particular interfaces. Only for more complex setups like load-
 balancing, does this behaviour cause problems.
arp_filter for the interface will be enabled if at least one of
 conf/{all,interface}/arp_filter is set to TRUE,
 it will be disabled otherwise

修改 /etc /sysctl.conf

net.ipv4.conf.all.arp_filter=1
net.ipv4.conf.default.arp_filter=1

寫一個批次檔

#!/bin/bash 
ip1="192.168.0.100"
ip2="192.168.0.101"
ip3="192.168.0.102" 
ip rule add from $ip1 table 10
ip route add table 10 default src $ip1 dev eth1 
ip rule add from $ip2 table 11
ip route add table 11 default src $ip2 dev eth2 
ip rule add from $ip3 table 12
ip route add table 12 default src $ip3 dev eth3