1

I have a server with 2 nics (interfaces) running ubuntu 14.10

I need to connect each nic to a different router (each being a gateway to different internet connections from different ISPs.

I also need the server to respond to requests from the same nic the request arrived from Requests from the server (update system etc) can go through either nic (load balance?)

So far whatever way i try it always comes back as only one nic works as any request from the other nic (aapparently) gets the response sent on the first and so the requester doesn't get the answer

Everytime i restart seems a different nic works and that doesn't work for me

Here's what i want

--[ISP1]-----------------|   |        |
     |-----------------{NIC1]|        |
                             | server |
     |-----------------[NIC2]|        |
--[ISP2]-----------------|   |        |

And here's my routing settings

route -n
Destino         Roteador        MáscaraGen.    Opções Métrica Ref   Uso Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    1      0        0 em1
0.0.0.0         192.168.0.1     0.0.0.0         UG    2      0        0 em2
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 em2
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 em1

netstat -rn
Destino         Roteador        MáscaraGen.    Opções   MSS Janela  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 em1
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 em2
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 em2
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 em1

after following @PedroPerez instructions i get:

route -n
Destino         Roteador        MáscaraGen.    Opções Métrica Ref   Uso Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 em1
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 em2
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 em1

netstat -rn
Destino         Roteador        MáscaraGen.    Opções   MSS Janela  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 em1
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 em2
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 em1

ip route show
default via 192.168.1.1 dev em1
192.168.0.0/24 dev em2  proto kernel  scope link  src 192.168.0.123
192.168.1.0/24 dev em1  proto kernel  scope link  src 192.168.1.123

ip route show table NOS
default via 192.168.1.1 dev em1
192.168.1.0/24 dev em1  scope link  src 192.168.1.123

ip route show table Vodafone
default via 192.168.0.1 dev em2
192.168.0.0/24 dev em2  scope link  src 192.168.0.123

Still only one address responds from outside

537mfb
  • 167
  • 1
  • 11
  • I'm no expert here, but looks like a routing issue. What's the output of `route -n` or `netstat -rn`? Also, what do you mean requests? What are you running on this server? – Gustavo Maia Feb 14 '15 at 11:45
  • @GustavoMaia added the requested info in the question - as for your questions - i have a http and mail server running on that machine and by request i mean like when a web page is requested. For testing i have some sites in one IP and others in the other and at any given moment only the ones on a single IP respond in the browser. On reboot it often changes which ones respond and which don't – 537mfb Feb 14 '15 at 12:41
  • @537mfb: Normal routing is not enough. You need to setup advanced routing rules to have more than one gateway! (See this link:http://lartc.org/howto/lartc.rpdb.multiple-links.html). – Khaled Feb 14 '15 at 12:48
  • i did something like this a few years ago ... tcpdump of TCP SYN packets drove code to add a route ... abandonded after route table hit 4000 entries ... use BGP and don't waste you time with asymmetric sources – Skaperen Feb 14 '15 at 12:58

1 Answers1

1

The answer your after is routing tables. At the moment you have two interfaces sharing the same routing table with two default routes (with different metric), but what you want is a completely separated second routing table for your second interface.

Either that or doing source NAT to all the traffic coming in from outside, which is a very bad idea anyway.

Routing tables in Linux

Check this tutorial, especially the part on how to setup split access which is what you're after.

Pedro Perez
  • 5,652
  • 1
  • 10
  • 11
  • been looking through the documentation but seems too technical and no praticality. Any pointers? – 537mfb Feb 14 '15 at 15:43
  • Sure, let me add an extra link on my answer with clear instructions. – Pedro Perez Feb 14 '15 at 22:31
  • i had seen that but couldn't make it work - with those routes set i now have what i will be putting up in a edit to my question - but still doesn't work (only responds through one address) – 537mfb Feb 16 '15 at 10:39
  • By the way - i didn't down vote you – 537mfb Feb 16 '15 at 10:40
  • actually after a couple of minutes it started working - thanks – 537mfb Feb 16 '15 at 10:50
  • Hey 537mfb. I don't know who downvoted me, but that's not an issue. The issue is that I'm not sure why and it'll be nice to know so I can do it better :) Glad to hear it works for you mate. – Pedro Perez Feb 16 '15 at 16:47
  • true - i just wanted to let you know it wasn't me - anyway seems either someone upvoted you or the dowbvote was removed - thanks again – 537mfb Feb 19 '15 at 10:09