linuxlinux-namespaces

netns: execute command from default namespace from another namespace


I ssh into a linux machine using nets namespace (command below)

ip netns exec NAME_SPACE ssh root@192.168.2.100

From there I want to execute some command(say "ifconfig") in default name space from this.


Solution

  • If you know that a process is running in the default network namespace (typically process number 1), you can use tools like nsenter to run a command in the same network namespace (-n option):

    # nsenter -t 1 -n ifconfig