Skip to content
Up To Date Time

Up To Date Time

  • Home
  • Sports
  • cryptocurrency
  • Technology
  • Virtual Reality
  • Education Law
  • More
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
  • Toggle search form
Network Namespace without Docker | Adaltas

Network Namespace without Docker | Adaltas

Posted on March 19, 2025 By rehan.rafique No Comments on Network Namespace without Docker | Adaltas

Let’s imagine the following use case:

  • I am connected to several networks (wlan0, eth0, usb0).
  • I want to choose which network I’m gonna use when I launch apps.
  • My app doesn’t allow me to choose a specific interface, it’s delegated to the OS that chooses the default one.

I could of course use Docker, which isolates networks, however Docker also isolates a lot of other things, needs images and is not really fit to launch existing apps on your computer.

We are going to use the same mechanism, network namespacing, but manually.

Let’s start by creating a network namespace named 4g:

Now we link an existing interface to it (we can use a virtual interface for complex setup but we’ll showcase it with the command line here).

Mine is named enp0s20u2:

sudo ip link set dev enp0s20u2 netns 4g

Once it’s done, the interface is not visible from the default namespace, let’s check it with:

Now that I hava configured the interface, I need to bind it to my 4g namespace. Either prefixing each of your commands or open a shell:

sudo ip netns exec 4g ip link set enp0s20u2 up
sudo ip netns exec 4g ip addr add 192.168.42.30/24 broadcast 192.168.42.255 dev enp0s20u2
sudo ip netns exec 4g ip route add default via 192.168.42.129

or

sudo ip netns exec 4g bash
> ip link set enp0s20u2 up
> ip addr add 192.168.42.30/24 broadcast 192.168.42.255 dev enp0s20u2
> ip route add default via 192.168.42.129
> exit

From now on it’s working but we don’t have a DNS.

DNS are usually set in /etc/resolv.conf and the namespace functionality offers a mapping system (default) /etc/netns//resolv.conf -> () /etc/resolv.conf

So let’s edit the file:

sudo mkdir -p /etc/netstat/4g
sudo echo "nameserver 8.8.8.8" > /etc/netstat/4g/resolv.conf

Now the namespace is fully functional. We can launch firefox for example:

sudo ip netns exec 4g firefox

Firefox is launched as root, which is not great. To fix it, use sudo:

USER=`whoami` sudo ip netns exec 4g sudo -u ${USER} firefox

Voila!

Technology

Post navigation

Previous Post: Meet Bake’s New Leadership: A Stronger Future Ahead
Next Post: The Athletic’s fundamental change

More Related Articles

How to create a YouTube video chapters’ timings generator using Gemini over Vertex AI How to create a YouTube video chapters’ timings generator using Gemini over Vertex AI Technology
Transforming App Development with AI: Series Overview Transforming App Development with AI: Series Overview Technology
How Does an IP Address Work? How Does an IP Address Work? Technology
A Deep Dive into Exciting New Features A Deep Dive into Exciting New Features Technology
Amazon launches Temu and Shein rival with ‘crazy low’ prices Amazon launches Temu and Shein rival with ‘crazy low’ prices Technology
Exploring the Realm of Form Control:Git and GitHub Preparing Session at PUSOE/PUSAT College Exploring the Realm of Form Control:Git and GitHub Preparing Session at PUSOE/PUSAT College Technology

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Sister-led social commerce startup Nectar lands $10.6M, reveals more about marketing tech
  • England vs India Test series gets a new name
  • Vietnamese Stop Importing Bitcoin Mining Rigs as Import Ban Looms
  • Apple May Finally Announce Vision Pro VR Controller Support Next Week
  • How to Bring Your Social Media Monetization Strategy to Email

Categories

  • cryptocurrency
  • Education Law
  • Sports
  • Technology
  • Virtual Reality

Copyright © 2025 Up To Date Time.

Powered by PressBook Blog WordPress theme