Testing LAN broadcast App with Linux Namespaces

Create Network Namespaces

ip netns add namespace1
ip netns add namespace2
ip netns add namespace3

Create the virtual interfaces

ip link add veth1 type veth peer name br-veth1
ip link add veth2 type veth peer name br-veth2
ip link add veth3 type veth peer name br-veth3
ip link set veth1 netns namespace1
ip link set veth2 netns namespace2
ip link set veth3 netns namespace3
ip netns exec namespace1 \
ip addr add 192.168.1.101/24 dev veth1
ip netns exec namespace2 \
ip addr add 192.168.1.102/24 dev veth2
ip netns exec namespace3 \
ip addr add 192.168.1.103/24 dev veth3

Create a bridge to join the interfaces

ip link add name br1 type bridge
ip link set br1 up
ip link set br-veth1 up
ip link set br-veth2 up
ip link set br-veth3 up
ip netns exec namespace1 ip link set veth1 up
ip netns exec namespace2 ip link set veth2 up
ip netns exec namespace3 ip link set veth3 up
ip link set br-veth1 master br1
ip link set br-veth2 master br1
ip link set br-veth3 master br1

Allow forwarding in the bridge

iptables -P FORWARD ACCEPT

Add IP address to the bridge

ip addr add 192.168.1.100/24 brd + dev br1

Execute the applications

ip netns exec namespace1 python app.py
ip netns exec namespace2 python app.py
ip netns exec namespace3 python app.py

The references I use

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Craft CMS vs WordPress: a side-by-side review

Automating Cloud Compliance with AWS OpsWorks for Chef Automate

New: Docker image for building forms

Automate the Fun Stuff with Python

The New Front-End Landscape

The Hacking Project — The French Web Dev Bootcamp

How to Estimate Software Development Time?

How to enable DevOps for High Performance

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matías Richart

Matías Richart

More from Medium

Odoo 14 dev ubuntu 20.04

Splunk Phantom REST API Filters

How to Install Linux Kernel 5.17 on AlmaLinux 8 / Fedora 35

Install Linux kernel

Whonix installation in Linux