🪟 Windows TippsWindows 10 weiter stabil - die Nutzerzahlen im August 2026(05.09.2026 um 18:20 Uhr)
🐧 Linux TippsCC2tv #433: Was CachyOS anders macht als Linux Mint 🐧️(29.08.2026 um 10:00 Uhr)
🔧 ProgrammierungArti 2.6.0 released(01.09.2026 um 02:00 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.393.0 (24.08.2026)(24.08.2026 um 17:26 Uhr)
🪟 Windows TippsGitHub Release: dependabot/dependabot-core v0.394.0 (31.08.2026)(31.08.2026 um 17:46 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.395.0 (07.09.2026)(07.09.2026 um 15:21 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.4.0 (26.08.2026)(26.08.2026 um 09:05 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vpython/v1.4.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)
🪟 Windows TippsWindows 10 weiter stabil - die Nutzerzahlen im August 2026(05.09.2026 um 18:20 Uhr)
🐧 Linux TippsCC2tv #433: Was CachyOS anders macht als Linux Mint 🐧️(29.08.2026 um 10:00 Uhr)
🔧 ProgrammierungArti 2.6.0 released(01.09.2026 um 02:00 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.393.0 (24.08.2026)(24.08.2026 um 17:26 Uhr)
🪟 Windows TippsGitHub Release: dependabot/dependabot-core v0.394.0 (31.08.2026)(31.08.2026 um 17:46 Uhr)
🔧 ProgrammierungGitHub Release: dependabot/dependabot-core v0.395.0 (07.09.2026)(07.09.2026 um 15:21 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vjavascript/v1.4.0 (26.08.2026)(26.08.2026 um 09:05 Uhr)
🔧 ProgrammierungGitHub Release: langwatch/scenario vpython/v1.4.0 (02.09.2026)(02.09.2026 um 04:47 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 4 Min Lesezeit
0

Linux : how to create network namespaces and bridge as docker does ?

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht
📺
dev.to

Docker or container runtimes implement multiple namespaces. For example, docker uses user, ipc, mount namespaces… and network namespaces.








Let’s define some variables



You’ll see it below, we’ll need to us and re-use many command line.



To avoid to edit again and again same values or if you want to change its, start by defining variables.




CODE
## Namespaces
NS1="x1"
NS2="x2"

## vethernet
VETH1="xeth1"
VETH2="xeth2"

## interfaces in ns
VPEER1="xpeer1"
VPEER2="xpeer2"

# ip provide for each interface
VPEER_ADDR1="10.11.0.10"
VPEER_ADDR2="10.11.0.20"

## bridge specifications
BR_ADDR="10.11.0.1"
BR_DEV="xavki0"






With that we have defined our namespaces name, our vethenet (those are as wire between namespace interface en the bridge), our vpeer (namespace interfaces), ip for each vpeer and finally the bridge.



With that we have defined our namespaces name, our vethenet (those are as wire between namespace interface en the bridge), our vpeer (namespace interfaces), ip for each vpeer and finally the bridge.



Remember that a bridge is like a virtual switch. You plug it on virtual or physical interface and create like a subnet behind it.






Create and configure our namespaces



I hope that you love the CLI ip netns ;)




CODE
## namespace creation
ip netns add $NS1
ip netns add $NS2


## create vethernet and plug it to interfaces
ip link add ${VETH1} type veth peer name ${VPEER1}
ip link add ${VETH2} type veth peer name ${VPEER2}

## add interfaces in each network
ip link set ${VPEER1} netns ${NS1}
ip link set ${VPEER2} netns ${NS2}

## activate vethernet
ip link set ${VETH1} up
ip link set ${VETH2} up


ip --netns ${NS1} a
ip --netns ${NS2} a


## activate all interfaces in each ns
ip netns exec ${NS1} ip link set lo up
ip netns exec ${NS2} ip link set lo up
ip netns exec ${NS1} ip link set ${VPEER1} up
ip netns exec ${NS2} ip link set ${VPEER2} up

## define an ip for each interface
ip netns exec ${NS1} ip addr add ${VPEER_ADDR1}/16 dev ${VPEER1}
ip netns exec ${NS2} ip addr add ${VPEER_ADDR2}/16 dev ${VPEER2}






So in the previous code :




  • we create our namespaces

  • we create our vethernet and plug it on namespace interface

  • we add interfaces on each namespace

  • we activate vethernets, loopbacks and interfaces

  • and set the ip for each interface






And now it’s time for the bridge



That’s it for namespaces but we need to plug on the bridge.




CODE
## create and activate the bridge xavki0
ip link add ${BR_DEV} type bridge
ip link set ${BR_DEV} up

## plug vethernet on the common bridge
ip link set ${VETH1} master ${BR_DEV}
ip link set ${VETH2} master ${BR_DEV}

## add an ip on the bridge
ip addr add ${BR_ADDR}/16 dev ${BR_DEV}

## add the default route in each namespace
ip netns exec ${NS1} ip route add default via ${BR_ADDR}
ip netns exec ${NS2} ip route add default via ${BR_ADDR}

## if you want an external access
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s ${BR_ADDR}/16 ! -o ${BR_DEV} -j MASQUERADE






First, we define a bridge with our variable and activate it.



Of course we connect on our bridge vethernets and we set an IP for our bridge.



To allow the communication from our namespaces to outside we need to create a default route to transfert packet through the bridge.



And finally, if you want to go outside of the host (of our namespaces), for example to go on internet, we authorize the ip forward and define a postrouting rule to accept routing with the bridge (input and output).



My original article here

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Windows 10 und 11: Update zerschießt Druckfunktion und PDF-Export
1 Quelle
Nvidia killt Windows-10-Support - Bald keine Game-Ready-Treiber mehr
1 Quelle
Windows 10 weiter stabil - die Nutzerzahlen im August 2026
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Linux : how to create network namespaces and bridge as docker does ?

Thematisch verwandte Begriffe: Linux, create, network, namespaces · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...