0

So I've Googled around quite a bit today for this, and tried several suggestions, but cannot get this to work. My setup is a VM with two virtual NICs, each with an IP from the same subnet/same default gateway:

[root][Primary][~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:07
      inet addr:10.192.101.150  Bcast:10.192.101.255  Mask:255.255.255.0
      inet6 addr: fe80::20c:29ff:fe2a:e307/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:2179 errors:0 dropped:0 overruns:0 frame:0
      TX packets:2147 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:231723 (226.2 KiB)  TX bytes:371444 (362.7 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0c:00:00:00:11
      inet addr:10.192.101.151  Bcast:10.192.101.255  Mask:255.255.255.0
      inet6 addr: fe80::20c:29ff:fe2a:e311/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:253 errors:0 dropped:0 overruns:0 frame:0
      TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:42116 (41.1 KiB)  TX bytes:798 (798.0 B)

lo        Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:12 errors:0 dropped:0 overruns:0 frame:0
      TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:720 (720.0 B)  TX bytes:720 (720.0 B)

(I've got an eth2 and eth3, but leaving that out to keep things simpler)

I then used the following to add routes for specific IPs to the specific interface:

ip route add 10.192.101.150 dev eth0
ip route add 10.192.101.151 dev eth1

My route -n then looks like:

[root][Primary][/etc/network]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.192.101.1    0.0.0.0         UG    0      0        0 eth0
10.192.101.150  0.0.0.0         255.255.255.255 UH    0      0        0 eth0
10.192.101.151  0.0.0.0         255.255.255.255 UH    0      0        0 eth1
[root][Primary][/etc/network]#

However, all of my eth1 traffic still continues to go out eth0. I've also tried it with and without the gateway 10.192.101.1 set on eth1 inside /etc/network/interfaces.

Does anyone know what I'm messing up here?

Editing to add...

One additional piece of information. When I do a ip route list I see this:

[root][Primary][~]# ip route list
default via 10.192.101.1 dev eth0
10.192.101.0/24 dev eth0  proto kernel  scope link  src 10.192.101.150
10.192.101.0/24 dev eth1  proto kernel  scope link  src 10.192.101.151
10.192.101.0/24 dev eth2  proto kernel  scope link  src 10.192.101.152

So that first line, I'm assuming, is why everything is going out eth0. I'm not looking for a different default gateway necessarily, just a different interface for that gateway to use based on the source IP (.151, etc). If I change that default gateway interface to eth1, it works, but then eth0 and every other interfaces traffic goes out that eth1 interface, not something I want.

  • 4
    Can you explain your setup? Why do eth1 and eth2 have IP addresses in the same network? Are you trying to bridge two segments of the network? Are you trying to get failover so that even if one link the machine is still connected to the network? What are you trying to achieve with this setup? – David Schwartz Apr 17 '17 at 21:36
  • Also, why have you added a static host route for your own NIC IP addresses? Generally, if you have two interfaces in the same subnet, you are doing something wrong and will likely suffer from issues with ARP flux and reverse path filtering. This smells like an XY-Problem. – Mark Riddell Apr 18 '17 at 12:23
  • @DavidSchwartz, The setup is a lab environment, where I am using NetFlow to watch the traffic and associate it with users, and want to see different IPs authenticate to our AD server. Right now if I hit the VM from .151 or .152 or anything else and authenticate, all outbound goes out .150 (eth0) and so all my AD users/sessions are mapped to the .150, where I'd like to see them on the IP I actually came in on. No failover or bridging or anything else. – Blackwater1977 Apr 18 '17 at 13:33
  • @MarkoPolo, That static route (10.192.101.0/24 dev eth0 proto kernel scope link src 10.192.101.150) could go, likely I was just copy/pasting and did not catch it. I had not considered ARP flux, so likely I'll just use different subnets for the interfaces as it seems like a headache now the way I was trying to do it. I was mostly wondering if I was doing something wrong, or it was easier and I was struggling from the dumbness. :) – Blackwater1977 Apr 18 '17 at 13:39
  • 1
    @Blackwater1977 I think you are missing a very fundamental thing about how Linux works, specifically that IP addresses belong to machines, not to interfaces. The interface is chosen based on proximity to the destination address. See this answer. – David Schwartz Apr 18 '17 at 13:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.