Wednesday, October 15, 2014

routing - Linux source address selection / binding on virtual interfaces

I have multiple virtual eth interfaces, some of which have the same gateway as the default gateway.



When I bind to the address of a virtual eth interface that doesn't have the same default gateway as eth0 everything works as expected and the proper source address is used. But when the gateway is the same, the source address selected for outgoing packets is always the main eth0 one. (seen in tcpdump as well). What am I doing wrong?



ubuntu 8.1 / Linux 2.6.27



I assume source address selection should work like this:
http://linux-ip.net/gl/ip-cref/node155.html




Example: (eth0 and eth0:2 have the same gateway)



eth0 is 10.81.61.46 mask 255.255.240.0 
eth0:1 10.250.50.70 mask 255.255.240.0
eth0:2 10.81.63.31 mask 255.255.240.0

route add default gw 10.81.48.254 dev eth0

ip rule add from 10.250.50.70 table second
ip route add default via 10.250.48.254 table second


ip rule add from 10.81.63.31 table third
ip route add default via 10.81.48.254 table third (adding "src 10.81.63.31" makes no diff)

wget --bind-address 10.81.61.46 whatismyip.net...
Result OK: 10.81.61.46

wget --bind-address 10.250.50.70 whatismyip.net..
Result OK: 10.250.50.70


wget --bind-address 10.81.63.31 whatismyip.net..
Result Not OK: 10.81.61.46

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...