A few years later..
Adding another answer.
First of all, I'm not sure if the ifconfig
package is maintained this days.
it is better to use the ip
command from the iproute2 package.
A few guides on iproute2
:
http://andys.org.uk/bits/2010/02/24/iproute2-life-after-ifconfig/
https://www.tecmint.com/ifconfig-vs-ip-command-comparing-network-configuration/
https://lartc.org/howto/lartc.iproute2.html#LARTC.IPROUTE2.WHY
Secondly, in your case I would probably use the simple Linux bridge also, But, it is also important to mention that since 2014 Open vSwitch (OVS) is a strong contender to the Linux Bridge.
Some references:
http://www.fiber-optic-transceiver-module.com/ovs-vs-linux-bridge-who-is-the-winner.html
https://devinpractice.com/2016/10/18/open-vswitch-introduction-part-1/
https://kumul.us/switches-ovs-vs-linux-bridge-simplicity-rules/
https://networkengineering.stackexchange.com/questions/28408/difference-between-linux-bridge-and-open-vswitch
Edit: I'll show how to connect two Linux namespaces using a bridge.
Solution #1 - Using Linux bridge (Notice - all ip
commands have a comment with 3#s on top):
# Variables
BRIDGE=my-bridge
TAP1=Tap1
TAP1-BR=TAP1-bridge-side
TAP2=Tap2
TAP2-BR=TAP2-bridge-side
NAMESPACE1=Namespace1
NAMESPACE2=Namespace2
## Create bridge
brctl addbr $BRIDGE
### Bring it up
ip link set dev $BRIDGE up
### Create a Veth pair named Tap1 <--> TAP1-bridge-side
ip link add $TAP1 type veth peer name $TAP1-BR
## Attach one side of Tap1 to bridge
brctl addif $BRIDGE $TAP1-BR
### And the other side to namespace1
ip link set $TAP1 netns $NAMESPACE1
### Set the interface on the bridge side up
ip link set dev $TAP1-BR up
### Set the interface inside the namespace up - notice that we execute 'ip netns exec' in order to run the inside the namespace scope
ip netns exec $NAMESPACE1 ip link set dev $TAP1 up
####
# Now create another Veth and connect it to the bridge - just change $TAP1 ->$TAP2, $TAP1-BR -> $TAP2-BR and repeat the same steps..
## Now you can reach namespace1 from namespace2 and vice versa.
Solution #2.A - Configuring a bridge using open VSwitch:
# Install the package
sudo apt-get install openvswitch-switch
# Now run the exact same commands like before just replace the CLI tool:
## brctl -> ovs-vsctl
# And replace commands:
## addbr -> add-br
## addif -> add-port
Solution #2.B - Configuring a bridge using open VSwitch - replace Veth pairs with internal ports:
# Similar to # 2.A
ovs-vsctl add-br $BRIDGE
# Similar to 2.A - Just with the addition of -- set Interface...
ovs-vsctl add-port $BRIDGE $TAP1 -- set Interface $TAP1 type=internal
### Similar #2.A (and #1)
ip link set $TAP1 netns $NAMESPACE1
### Similar #2.A (and #1)
ip netns exec $NAMESPACE1 ip link set dev $TAP1 up
# Now repeat for $TAP2...