Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I tell the networking stack which ip to be the source (src) to communicate with in the case of multiple ips on a virtual interface?

auto eth0 
iface eth0 inet static
            address x.x.x.209
            netmask 255.255.255.0
            network x.x.x.0
            broadcast x.x.x.255
            gateway x.x.x.254

auto eth0:1
iface eth0:1 inet static
            address x.x.x.210
            netmask 255.255.255.0
            network x.x.x.0
            broadcast x.x.x.255
            gateway x.x.x.254

etc. etc.

It seems to be picking the last one in /etc/networking/interfaces

~# ip -s route get 173.194.67.113; 
173.194.67.113 via x.x.x.254 dev eth0  src x.x.x.210 
  cache  users 1 used 11 mtu 1500 advmss 1460 hoplimit 64

But this behaviour is unpredictable I have about 30 ip's assigned per interface, and sometimes the (scr) source ip changes.

I need to understand how it chooses.

I've tried setting metric to standardize the src but it doesn't appear to support virtual interfaces. NETLINK: Packet too small or truncated!

EDIT: Ubuntu 10.04 64bit

EDIT Following @TheCleaner's link my /etc/network/interfaces is now a lot cleaner. Sorry for not providing more information earlier, It's a complicated environment, and all I really wanted to know is how the kernel decides the source address when you run say an apt-get update from the command line. All the load banacing stuff, failover etc is working great.

auto eth0
iface eth0 inet static
            address x.x.x.183
            netmask 255.255.255.0
            network x.x.x.0
            broadcast x.x.x.255
            gateway x.x.x.254
up ip addr add x.x.x.209 dev eth0 label eth0:1
up ip addr add x.x.x.210 dev eth0 label eth0:2
up ip addr add x.x.x.211 dev eth0 label eth0:3
up ip addr add x.x.x.212 dev eth0 label eth0:4
up ip addr add x.x.x.213 dev eth0 label eth0:5
up ip addr add x.x.x.214 dev eth0 label eth0:6
up ip addr add x.x.x.215 dev eth0 label eth0:7

IDK if its fixed. but so far so good. I'm just going to run while sleep 5; do ip -s route get 173.194.67.113; done
for some time to see if i have a stable ip when connecting outbound.

This is working great! thanks everyone who chimed in. I'm still curios as to WHY exactly my source ip was changing, but ill just chalk it up to having an improperly written interfaces file and move on.

share|improve this question
    
Which OS (and Distribution if Linux) does this relate to? –  EightBitTony Apr 30 '12 at 18:33
    
Take a look at this: serverfault.com/questions/232844/… (look at Craig's answer) –  TheCleaner Apr 30 '12 at 19:30
    
When the source ip address changes, this is all for connections being established outwards? Do you ever change the IPs assigned, or are they the same 30 addresses always? –  becomingwisest Apr 30 '12 at 19:44
1  
The IP's are static and are also shared with another machine (via keepalived and VRRP) In addition to the shared ips, each server has one unique ip assigned. It its the unique IP that I want to force all outgoing connections to take. (so I can have proper networking on both machines (security updates and such) The server is serving as a load balancer with haproxy. I've given the server multiple ips as this is the easiest way to direct traffic in haproxy (I don't want to inspect headers) –  foocorpluser Apr 30 '12 at 20:07
    
And what is you actual goal? BTW - did you try to set the netmask of logical IPs to 255.255.255.255? –  Nils Apr 30 '12 at 20:18

1 Answer 1

In the alias stanza, do not include the gateway. You also don't need the 'network' line at all.

auto eth0 
iface eth0 inet static
            address x.x.x.209
            netmask 255.255.255.0
            broadcast x.x.x.255
            gateway x.x.x.254

auto eth0:1
iface eth0:1 inet static
            address x.x.x.210
            netmask 255.255.255.0
share|improve this answer
    
this line? -> gateway x.x.x.254 –  foocorpluser Apr 30 '12 at 20:56
    
Yes, I have extended my answer. –  hayalci Apr 30 '12 at 21:01
    
okay, I assume it will inherit the broadcast and gateway setting from the parent, makes sense. thanks. –  foocorpluser Apr 30 '12 at 21:03
    
Hayalci's answer is vaguely documented in /usr/share/doc/initscripts-*/sysconfig.txt, which says " the network numbers might be different, but everything else might be the same," –  Stefan Lasiewski May 1 '12 at 14:20
    
just a follow-up Bcast was not inherited from the parent, gateway was. –  foocorpluser Jun 8 '12 at 18:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.