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.

Using IP aliasing a linux box has bound multiple ip addresses from the same subnet on the same NIC. So ifconfig shows up device eth0 with , eth0:1 with and eth0:2 with .

How does Linux determine the IP source address used for outgoing ip traffic? Is there a way to define what source IP address certain outgoing traffic should use?

share|improve this question
1  
Just specify a netmask of 255.255.255.255 for the IPs you don't want to be used as source addresses. That will make them seem "further" from the default gateway (and other machines on that subnet) and so they won't be preferred. See here –  David Schwartz Sep 3 '12 at 10:52
    
This helps at least partially. Can alternativly iptables be used for specifiying the source IP on outgoing stuff here? –  Stefan Armbruster Sep 3 '12 at 11:22
    
Yes, but that's not the best way to do it. Better is something like ip route replace default via GATEWAY.IP.GOES.HERE src SOURCE.IP.GOES.HERE –  David Schwartz Sep 3 '12 at 12:18
add comment

1 Answer

up vote 6 down vote accepted

I'm not sure why he posted his answer as a comment, but David Schwartz is correct, you should set a netmask of 255.255.255.255 on the 'secondary' addresses, and you should not set gateway addresses on them. You put the correct netmask on the main address, and give it the correct gateway address.

share|improve this answer
add comment

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.