User Tools

Site Tools


linux:netns

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
linux:netns [2025/08/15 16:33] jonathanlinux:netns [2025/08/15 16:55] (current) jonathan
Line 1: Line 1:
 ===== Linux - NETNS ===== ===== Linux - NETNS =====
 +This Bash script creates three separate Linux network namespaces (instance1, instance2, and instance3), assigns a specific physical interface to each, configures their IPv4/IPv6 addresses and default routes, and sets custom DNS resolvers for each namespace.
 <code - /usr/local/share/instances-netns.sh> <code - /usr/local/share/instances-netns.sh>
 #!/bin/bash #!/bin/bash
Line 34: Line 34:
 echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4" | sudo tee /etc/netns/instance3/resolv.conf > /dev/null echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4" | sudo tee /etc/netns/instance3/resolv.conf > /dev/null
 </code> </code>
 +\\ 
 +This Bash script displays the network interface details, IPv4/IPv6 addresses, and routing tables for three network namespaces (instance1, instance2, and instance3) in a formatted, sectioned output.
 <code - show-netns-settings.sh> <code - show-netns-settings.sh>
 #!/bin/bash #!/bin/bash
Line 76: Line 77:
 echo "################################################" echo "################################################"
 </code> </code>
 +\\ 
 +This script opens firefox-esr in three different network namespaces (instance1, instance2, instance3), each using its own browser profile and with proxy settings disabled.
 <code - netns-firefox.sh> <code - netns-firefox.sh>
 #####Note that it isn't compatible with Firefox snap version. The firefox-esr must be installed.##### #####Note that it isn't compatible with Firefox snap version. The firefox-esr must be installed.#####
Line 91: Line 93:
 env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY firefox-esr --new-instance --profile $HOME/.mozilla/instance3 env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY firefox-esr --new-instance --profile $HOME/.mozilla/instance3
 </code> </code>
 +\\ 
 +This script runs speedtest-cli inside three network namespaces (instance1, instance2, instance3) with proxy variables cleared, allowing separate network speed tests for each namespace.
 <code - netns-speedtest.sh> <code - netns-speedtest.sh>
 #!/bin/bash #!/bin/bash
Line 103: Line 106:
 sudo -u $USER \ speedtest-cli sudo -u $USER \ speedtest-cli
 </code> </code>
 +\\ 
 +This systemd unit file defines a one-shot service that runs the /usr/local/share/instances-netns.sh script at boot after the network is up and remains marked active after execution.
 <code - /etc/systemd/system/instances-netns.service> <code - /etc/systemd/system/instances-netns.service>
 [Unit] [Unit]
Line 117: Line 121:
 WantedBy=multi-user.target WantedBy=multi-user.target
 </code> </code>
 +\\ 
 +These commands reload systemd to recognize new or changed units, enable the instances-netns.service to start at boot, and start the service immediately.
 <code - Activate the new service> <code - Activate the new service>
 sudo systemctl daemon-reload sudo systemctl daemon-reload
linux/netns.1755275628.txt.gz · Last modified: by jonathan