Emulate LAN infra using Virtualization techniques
https://youtu.be/DgjAbMyGLak

Emulate LAN infra using Virtualization techniques

#/bin/bash 

# Refer https://youtu.be/DgjAbMyGLak  for the explanation of this script

# To build a basic virtual network using Network Namespaces(Micro containers) 
# emulating 2 hosts 
# and a linux bridge emulating a ethernet switch 


# Create namespaces or micro Containers C1 and C2 emulating 2 hosts 
ip netns add C1 
ip netns add C2 


# Create a linux bridge br0 
BRIDGE0=br0 
brctl addbr $BRIDGE0 
brctl stp $BRIDGE0 off 
ip link set dev $BRIDGE0 up 


# Create 2 veth pair (v1,v2) and (v3,v4) 
ip link add v1 type veth peer name v2 
ip link add v3 type veth peer name v4 


# Interconnecting Container C1 and Linux Bridge br0 
brctl addif $BRIDGE0 v2                               # Connect v2 to bridge br0 
ip link set v1 netns C1                               # Connect v1 to C1 


ip netns exec C1 ip addr add 10.10.10.2/24 dev v1   # Assign IP addr for v1 in C1 


ip netns exec C1 ip link set dev v1 up                # Bring up v1 in C1 
ip link set dev v2 up                                 # Bring up v2 in bridge br0 

# Interconnecting Container C2 and Linux Bridge br0 
brctl addif $BRIDGE0 v4                               # Connect v4 to bridge br0 
ip link set v3 netns C2                               # Connect v3 to C2 


ip netns exec C2 ip addr add 10.10.10.3/24 dev v3   # Assign IP addr for v3 in C2 


ip netns exec C2 ip link set dev v3 up                # Bring up v3 in C2 
ip link set dev v4 up                                 # Bring up v4 in bridge br0*

******************************************************************************#

!/bin/bash 


  # exp 1 
  # To bring down the topology setup in exp 1 


  ip netns exec C1 ip link set dev v1 down  # Bring down the interface v1 in C1  
  ip netns exec C2 ip link set dev v3 down  # Bring down the interface v3 in C2 


  ip link set dev v2 down                    # Bring down interface v2 
  ip link set dev v4 down                    # Bring down interface v4 


  brctl delif br0 v2                  # Detach interface v2 from the bridge br0 
  brctl delif br0 v4                  # Detach interface v4 from the bridge br0 


  ip link set dev br0 down                   # Bring down the interface br0 


  ip link del dev v2                         # Delete veth pair (v1,v2) 
  ip link del dev v4                         # Delete veth pair (v3,v4) 


  brctl delbr br0                            # Delete the bridge br0 


  ip netns del C1                            # Delete the micro Container C1 
  ip netns del C2                            # Delete the micro Container C2
  


Refer https://youtu.be/DgjAbMyGLak for the explanation of this script

To view or add a comment, sign in

More articles by Prabhunath Govindappa

  • Creating VxLAN/Overlay Network

    Refer here for the discussion of this topic: https://www.youtube.

  • VLAN Emulation with DHCP

    Go here for the discussion -- https://youtu.be/-D_WcyrGvvc #!/bin/bash # Experiment: #        To understand vlan as a…

  • VLAN emulation using Virtualization

    Go here for discussion - https://youtu.be/LuKP7SC055o #!/bin/bash # Experiment: #        To understand vlan as a…

Others also viewed

Explore content categories