Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an AWS instance with multiple virtual network interfaces all having different elastic IPs. Since I crawl from this machine, the IPs often get blocked. Distributing the outgoing traffic through all these interfaces will prevent it since all are mapped to different elastic IPs.

eth0      Link encap:Ethernet  HWaddr 0A:E6:A3:DD:F1:E0  
          inet addr:10.0.0.120  Bcast:10.0.0.127  Mask:255.255.255.128
          inet6 addr: fe80::8e6:a3ff:fedd:f1e0/64 Scope:Link

eth0:0    Link encap:Ethernet  HWaddr 0A:E6:A3:DD:F1:E0  
          inet addr:10.0.0.122  Bcast:10.0.0.127  Mask:255.255.255.128
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:1    Link encap:Ethernet  HWaddr 0A:E6:A3:DD:F1:E0  
          inet addr:10.0.0.18  Bcast:10.0.0.127  Mask:255.255.255.128
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

I want to send my outgoing traffic from all the network interfaces in a round robin fashion. Since these are virtual interfaces I can't achieve this using the iproute2 package. Can someone tell me how I can achieve this ?

share|improve this question
2  
Why can't you use the iproute2 suite? All you need to do is change the default route. –  Patrick Jan 28 at 13:17
    
@Patrick: Actually whenever i try to create a new routing table(alternate) and add a route saying ip route add default dev eth0:0 table alternate, it picks eth0 instead of eth0:0 –  pradeepchhetri Jan 29 at 4:27

1 Answer 1

up vote 2 down vote accepted

You can use the iproute2 suite for this. The fact that the source IPs are assigned to interface aliases has no impact on the issue.

Lets assume your default gateway is 10.0.0.1

ip route del default
ip route add default via 10.0.0.1 dev eth0 src 10.0.0.122

That's it. Just replace the default route with the second line, replacing 10.0.0.122 with the source IP you want to route traffic out of.


If you want to use all your IPs at the same time, just assign them each certain subnets instead:

ip route add 64.0.0.0/2 via 10.0.0.1 dev eth0 src 10.0.0.122
ip route add 128.0.0.0/2 via 10.0.0.1 dev eth0 src 10.0.0.18

This will make any outbound traffic to 64.0.0.0 - 127.255.255.255 use 10.0.0.122, and 128.0.0.0 - 191.255.255.255 use 10.0.0.18. All other traffic will use the default of 10.0.0.120


The fact that the IPs are assigned to interface aliases (eth0:0) has absolutely no impact. IProute2 (or really the kernel) doesn't care.
And yes, I tried this on my home network, it works just fine.

share|improve this answer
    
Thank you for the reply but in this case you are hardcoding the destination ips . I dont want to do that .. I want to say lets say packet 1 to IP 1.1.1.1 through eth0:0 and packet 2 to IP 1.1.1.1 through eth0:1 –  pradeepchhetri Jan 29 at 7:20
    
Thank you patrick for your answer. I modified the ip route command to use source port instead of destination ip as the method of load balancing. –  pradeepchhetri Jan 29 at 12:45

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.