08/12/27 07:35:52 opgamkt1
いや、ポリシールーティングの設定はいる。
けど、fwmark使わずに、ソースアドレスでテーブルを振り分ける。
echo "127 net1" >> /etc/iproute2/rt_tables
echo "126 net2" >> /etc/iproute2/rt_tables
ip route add $network1 dev $if1 scope link src $ip1 table net1
ip route add $network2 dev $if2 scope link table net1
ip route 127.0.0.0/8 dev lo scope link table net1
ip route default via $gw1 dev $if1 table net1
ip route $network2 dev $if2 scope link src $ip2 table net2
ip route $network1 dev $if1 scope link table net2
ip route 127.0.0.0/8 dev lo scope link table net2
ip route default via $gw2 dev $if2 table net2
ip rule add from $ip1 table net1 prio 14998
ip rule add from $ip2 table net2 prio 14999
いわゆる、参考文献でよく見る基本形
・localのbindによって、gw1とgw2を振り分ける。
・localのbindがanyの場合は、mainテーブルのdefault gatewayによってlocalのbindが確定する
・listenしているソケットがanyの場合は、acceptしてlocal側のbindが確定した段階で、
出力先のネットワークが確定する。つまり、受け取ったif側のgwが使用される
・wgetにはbindaddress指定があるので、
wget --bind-address=${ip1} URLリンク(hogehoge)<) ではgw2
wget URLリンク(hogehoge) ではmainテーブルで指定したgw
に向かってパケットが投げられる