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
Next revision
Previous revision
linux:netns [2025/08/15 16:27] 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 - instances-netns.sh>+<code - /usr/local/share/instances-netns.sh>
 #!/bin/bash #!/bin/bash
 ip netns add instance1 ip netns add instance1
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 102: Line 105:
 sudo /usr/sbin/ip netns exec instance3 env http_proxy="" https_proxy="" \ sudo /usr/sbin/ip netns exec instance3 env http_proxy="" https_proxy="" \
 sudo -u $USER \ speedtest-cli sudo -u $USER \ speedtest-cli
 +</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>
 +[Unit]
 +Description=Run CPE Netns Script at Boot
 +After=network.target
 +
 +[Service]
 +Type=oneshot
 +ExecStart=/usr/local/share/instances-netns.sh
 +RemainAfterExit=yes
 +
 +[Install]
 +WantedBy=multi-user.target
 +</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>
 +sudo systemctl daemon-reload
 +sudo systemctl enable instances-netns.service
 +sudo systemctl start instances-netns.service
 </code> </code>
linux/netns.1755275275.txt.gz · Last modified: by jonathan