0

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
Zypher
  • 36,995
  • 5
  • 52
  • 95

2 Answers2

1

Please try to add addresses via

ip addr add 10.250.50.70/20 dev eth0
ip addr add 10.81.63.31/20 dev eth0

Now i setup same configuration on my server, and it works fine:

ip addr add x.20.28.100/24 dev eth0
ip addr add x.20.28.101/24 dev eth0
ip rule add from x.20.28.100 table 100
ip rule add from x.20.28.101 table 101
ip ro add default via  x.20.28.1 table 100
ip ro add default via  x.20.28.1 table 101
echo -n "RESULT: "; wget --bind-address x.20.28.100   http://www.whatismyip.com/automation/n09230945.asp -q -O - ; echo
RESULT: x.20.28.100
echo -n "RESULT: "; wget --bind-address x.20.28.101   http://www.whatismyip.com/automation/n09230945.asp -q -O - ; echo
RESULT: x.20.28.101

PS: also you can try http://proxy-check.com/

PS2: Do you have any NAT?

vlad
  • 844
  • 2
  • 6
  • 13
0

Here is the explnation how linux determine SRC IP to use what

https://unix.stackexchange.com/a/611945/214557

Alex
  • 262
  • 3
  • 6