1

I have followed many articles available on serverfault but i am not able to manage outbound traffic through 2nd nics in ubuntu 16.04.

other than serverfault i followed - https://kindlund.wordpress.com/2007/11/19/configuring-multiple-default-routes-in-linux/

https://aws.amazon.com/premiumsupport/knowledge-center/ec2-ubuntu-secondary-network-interface/

https://msazure.club/configure-ubuntu-to-support-multiple-nics-in-azure/

My configuration - tried on AWS and Azure

Two ips

1st Nic - 172.31.29.87, 
2nd nic - 172.31.17.222

Create route table

bash -c "echo '1 eth1route' >> /etc/iproute2/rt_tables"

Create eth1 nic file

/etc/network/interfaces.d/eth1.cfg

  auto eth1
  iface eth1 inet dhcp
     post-up ip route add 172.31.16.0/20 dev eth1 src 172.31.17.222 table eth1route 
     post-up ip route add default via  172.31.16.1  dev eth1 table eth1route
     post-up ip rule add from 172.31.17.222/32 table eth1-rt
     post-up ip rule add to 172.31.17.222/32 table eth1-rt

then ifdown eth1 and ifup eth1

ip r

default via 172.31.16.1 dev eth0
172.31.16.0/20 dev eth0  proto kernel  scope link  src 172.31.29.87
172.31.16.0/20 dev eth1  proto kernel  scope link  src 172.31.17.222

route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.31.16.1     0.0.0.0         UG    0      0        0 eth0
172.31.16.0     0.0.0.0         255.255.240.0   U     0      0        0 eth0
172.31.16.0     0.0.0.0         255.255.240.0   U  

0 0 0 eth1

ip rule show

0:      from all lookup local
32765:  from 72.31.17.222 lookup 1000
32766:  from all lookup main
32767:  from all lookup default

after all above configuration i can connect to both ips( incoming on both nics) but outgoing traffic only from eth0.

Could you please help me how can enable outbound traffic on both NICs ?

sanjayparmar
  • 623
  • 8
  • 18
  • What is your purpose for using two NICs? Do you want simple load balancing (though I doubt your effective throughput would increase) or do you need redundancy in case of subnet failure (though again I doubt you'd get an actual benefit here for a cloud-based server since both NICs would use the same subnet)? Or do you want different traffic to take a different path for some reason? – Jeff Learman Oct 18 '19 at 13:47
  • There are limitations per nic in cloud Base servers so if you add multiple nics, would increase throughput. – sanjayparmar Oct 18 '19 at 17:43

1 Answers1

1

You can probably create a route like this instead of your default route that would use both links. (untested)

ip route add default scope global \
    nexthop via 172.31.16.1 dev eth0 weight 1 \
    nexthop via 172.31.16.1 dev eth1 weight 1

If you need to combine the capacity of two links you would be better off using some kind of bonding though. But that does require support on the system you are connected to.

Zoredache
  • 128,755
  • 40
  • 271
  • 413