0

I've created a pair of veth s in linux. If i assign it an ip address where the network part is the same as eth0, networking seems to break. For instance an eth0 192.168.0.3, veth1 192.168.0.100. On the other hand, every indication from ip a/l says everything is up, but ping/nc etc, will not work in the local and remote host.

Is there a limitation written somewhere about this?

2
  • 1
    Why do you need 2 interfaces within the same subnet? Consider assigning multiple IPs to a sinlge interface.
    – Panki
    Oct 22, 2021 at 9:50
  • Because i'm trying out the iproute2 commands for creating interfaces Oct 29, 2021 at 3:48

1 Answer 1

0

There are general networking principles that say different subnets need a different subnet IP range and have only one interface into a subnet on a particular machine.

You can violate those principles, but then it's on you to make this work (and it will need effort, like having applications bind to a particular interface).

The veth pair forms a subnet. If you put both veth interfaces are in the same networking namespace, and assign IP addresses like in the question, then you have now violated both principles. So that's not working.

You typically move one of the veth pair into a different networking namespaces (because that's what veth pairs are meant for: connect networking namespaces), and you give the one veth that's visible a different subnet, and you assign to both veth interfaces addresses in that subnet.


But having the same network address on the host veth in the host namespace kills the main interface.

Yes. That's why you create a different subnet on the veth pair, and do routing, just like with any normal subnet.

And if this is an XY problem, and you want to achieve something specific, please edit your question and state your goal. There are other ways to do networking in containers (e.g. a macvlan).

You don't necessarily need to create a bridge to get different network segments to forward to each other,

But you need to if you want to have the same subnet both in the name namespace, and in the other namespace. (Or you use a macvlan).

As long as you try to put the "same" network address somewhere, or the "same" subnet on different interfaces, your routing is not going to work.

4
  • Routers for instance have different interfaces with the same subnets. In any case, the routing table can be altered to route packets to the correct interface. IIRC in a multi homed machine, linux allows this, but with the veths it doesn't. Oct 22, 2021 at 17:18
  • 1
    Routers use bridging for that... And yes, you can spend effort to make everything work, but you need to spend the effort. The same strategy works for veths, but you need to know what you are doing. With both ends of the veth in the same network namespace, you'll have a routing loop, so you need to know how to disable routing loop detection to make it work. Which is not something you want to do usually, because the whole setup is just wrong.
    – dirkt
    Oct 23, 2021 at 6:04
  • I've shifted one end of the veth into another namespace, which is what any containerization product does. But having the same network address on the host veth in the host namespace kills the main interface. You don't necessarily need to create a bridge to get different network segments to forward to each other, so long as the routing tables specify which link gets which traffic. Oct 25, 2021 at 5:07
  • ^different hosts^ Oct 25, 2021 at 5:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .