Can I create three “veth” interfaces to build a virtual LAN in Linux?

0

In Linux with iproute2, I knew how to create two veth (Virtual Ethernet) NICs and separated them into two network namespaces, then I got two virtual NICs and virtual 'cable' connected them.

Now I want to build a LAN in further, which should have three NICs, each has a single IP address and form a network segment.

Can I use veth (or whatever makes sense) to achieve this?

Woody Wu

Posted 2018-08-13T01:17:27.380

Reputation: 3

Answers

1

veths always come in pairs.

If you want to build a network segement with more than two virtual NICs you will need to combine veths with bridging.

So lets say we have three network namespaces, lets call them “red,” “green” and “blue,” which we want to build a network segment between. We need to (names used are arbitary).

  • Choose one of the network namespaces to hold the bridge, lets choose green.
  • Create two veth pairs, veth0/veth1 and veth2/veth3.
  • Put the veths into the network namespaces, veth0 -> “red” veth1 -> “green” veth2 -> “green” veth3 -> “green.”
  • Create a bridge br0 in “green” bridging veth1 and veth2.
  • Assign IP addresses/masks to veth0 in “red,” br0 in “green” and veth2 in “blue.”

plugwash

Posted 2018-08-13T01:17:27.380

Reputation: 4 587

Thanks. I endded up with using of bridge to connect one end of all the pairs. – Woody Wu – 2018-08-18T02:57:09.487

0

Yes, you can make arbitrarily complicated LANs this way. I regularly do this with a few scripts (starting an xterm or two in every network namespace helps). Note you need routes in every network namespace.

There are also a dozen or so applications which simulate a LAN in this way and give you a GUI to create and manage them.

Edit

Here is a list with more than a dozen applications; googling will probably turn up more.

dirkt

Posted 2018-08-13T01:17:27.380

Reputation: 11 627

Cool, I never though there are applications already. Can you point me to one of them? – Woody Wu – 2018-08-18T06:43:19.050