I'm trying to isolate outbound network traffic to a specific target for metering purposes, so I thought I'd route it via a dedicated IP address. In order to achieve this I have setup a subinterface eth0:1, which appears as follows:

# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast  state UP group default qlen 1000
link/ether fa:16:3e:42:ae:d3 brd ff:ff:ff:ff:ff:ff
inet brd scope global eth0
   valid_lft forever preferred_lft forever
inet brd scope global secondary eth0:1
   valid_lft forever preferred_lft forever

So far so good. The routing piece that's supposed to make it work is this:

# ip route add via dev eth0:1

When I check the routing table, I get:

# ip route list
default via dev eth0 via dev eth0 dev eth0  proto kernel  scope link  src 

Notice the 2nd line, which ends in dev eth0 rather than eth0:1 as I'd expect but so far this could just be a display issue. However, when observing the traffic using tcpdump, it's obvious the route is behaving as the above display suggests, ie: traffic to transits via the main interface eth0, using its IP rather than eth0:1's IP

The weird thing is that if I use a dedicated NIC (eth1) rather than a subinterface as above, everything works as expected. Is this a limitation of subinterfaces, a bug or am I doing smth wrong?

The OS is Ubuntu 14.04.3 server running on kernel 3.13.0-76. It's a guest VM hosted on a KVM hypervisor (though I doubt this is a factor).


You should be able to accomplish what you want using this command:

ip route add dev eth0:1 src

If you enter ip route list you should see the change of src.

  • Many thanks Oliver; the only thing I had to add was the next hop, as in: ip route add via dev eth0:1 src; this works flawlessly. Thanks again! – sxc731 Feb 3 '16 at 13:03
  • Actually, you don't even need "dev eth0:1". – Laszlo Valko Feb 4 '16 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.