{
    "mode": "man",
    "parameter": "ip-netns",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/ip-netns/8/json",
    "generated": "2026-06-15T16:02:06Z",
    "synopsis": "ip [ OPTIONS ] netns  { COMMAND | help }\nip netns [ list ]\nip netns add NETNSNAME\nip netns attach NETNSNAME PID\nip [-all] netns del [ NETNSNAME ]\nip netns set NETNSNAME NETNSID\nNETNSID := auto | POSITIVE-INT\nip netns identify [ PID ]\nip netns pids NETNSNAME\nip [-all] netns exec [ NETNSNAME ] command...",
    "sections": {
        "NAME": {
            "content": "ip-netns - process network namespace management\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "ip [ OPTIONS ] netns  { COMMAND | help }\n\nip netns [ list ]\n\nip netns add NETNSNAME\n\nip netns attach NETNSNAME PID\n\nip [-all] netns del [ NETNSNAME ]\n\nip netns set NETNSNAME NETNSID\n\nNETNSID := auto | POSITIVE-INT\n\nip netns identify [ PID ]\n\nip netns pids NETNSNAME\n\nip [-all] netns exec [ NETNSNAME ] command...\n",
            "subsections": [
                {
                    "name": "ip netns monitor",
                    "content": "ip netns list-id [ target-nsid POSITIVE-INT ] [ nsid POSITIVE-INT ]\n\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "A network namespace is logically another copy of the network stack, with its own routes,\nfirewall rules, and network devices.\n\nBy default a process inherits its network namespace from its parent. Initially all the pro‐\ncesses share the same default network namespace from the init process.\n\nBy convention a named network namespace is an object at /run/netns/NAME that can be opened.\nThe file descriptor resulting from opening /run/netns/NAME refers to the specified network\nnamespace. Holding that file descriptor open keeps the network namespace alive. The file de‐\nscriptor can be used with the setns(2) system call to change the network namespace associated\nwith a task.\n\nFor applications that are aware of network namespaces, the convention is to look for global\nnetwork configuration files first in /etc/netns/NAME/ then in /etc/.  For example, if you\nwant a different version of /etc/resolv.conf for a network namespace used to isolate your vpn\nyou would name it /etc/netns/myvpn/resolv.conf.\n\nip netns exec automates handling of this configuration, file convention for network namespace\nunaware applications, by creating a mount namespace and bind mounting all of the per network\nnamespace configure files into their traditional location in /etc.\n\n",
            "subsections": [
                {
                    "name": "ip netns list - show all of the named network namespaces",
                    "content": "This command displays all of the network namespaces in /run/netns\n\n"
                },
                {
                    "name": "ip netns add NAME - create a new named network namespace",
                    "content": "If NAME is available in /run/netns this command creates a new network namespace and\nassigns NAME.\n\n"
                },
                {
                    "name": "ip netns attach NAME PID - create a new named network namespace",
                    "content": "If NAME is available in /run/netns this command attaches the network namespace of the\nprocess PID to NAME as if it were created with ip netns.\n\n"
                },
                {
                    "name": "ip [-all] netns delete [ NAME ] - delete the name of a network namespace(s)",
                    "content": "If NAME is present in /run/netns it is umounted and the mount point is removed. If\nthis is the last user of the network namespace the network namespace will be freed and\nall physical devices will be moved to the default one, otherwise the network namespace\npersists until it has no more users. ip netns delete may fail if the mount point is in\nuse in another mount namespace.\n\nIf -all option was specified then all the network namespace names will be removed.\n\nIt is possible to lose the physical device when it was moved to netns and then this\nnetns was deleted with a running process:\n\n$ ip netns add net0\n$ ip link set dev eth0 netns net0\n$ ip netns exec net0 SOMEPROCESSINBACKGROUND\n$ ip netns del net0\n\nand eth0 will appear in the default netns only after SOMEPROCESSINBACKGROUND will\nexit or will be killed. To prevent this the processes running in net0 should be killed\nbefore deleting the netns:\n\n$ ip netns pids net0 | xargs kill\n$ ip netns del net0\n\n"
                },
                {
                    "name": "ip netns set NAME NETNSID - assign an id to a peer network namespace",
                    "content": "This command assigns a id to a peer network namespace. This id is valid only in the\ncurrent network namespace.  If the keyword \"auto\" is specified an available nsid will\nbe chosen.  This id will be used by the kernel in some netlink messages. If no id is\nassigned when the kernel needs it, it will be automatically assigned by the kernel.\nOnce it is assigned, it's not possible to change it.\n\n"
                },
                {
                    "name": "ip netns identify [PID] - Report network namespaces names for process",
                    "content": "This command walks through /run/netns and finds all the network namespace names for\nnetwork namespace of the specified process, if PID is not specified then the current\nprocess will be used.\n\n"
                },
                {
                    "name": "ip netns pids NAME - Report processes in the named network namespace",
                    "content": "This command walks through proc and finds all of the process who have the named net‐\nwork namespace as their primary network namespace.\n\n"
                },
                {
                    "name": "ip [-all] netns exec [ NAME ] cmd ... - Run cmd in the named network namespace",
                    "content": "This command allows applications that are network namespace unaware to be run in some‐\nthing other than the default network namespace with all of the configuration for the\nspecified network namespace appearing in the customary global locations. A network\nnamespace and bind mounts are used to move files from their network namespace specific\nlocation to their default locations without affecting other processes.\n\nIf -all option was specified then cmd will be executed synchronously on the each named\nnetwork namespace even if cmd fails on some of them. Network namespace name is printed\non each cmd executing.\n\n"
                },
                {
                    "name": "ip netns monitor - Report as network namespace names are added and deleted",
                    "content": "This command watches network namespace name addition and deletion events and prints a\nline for each event it sees.\n\n"
                },
                {
                    "name": "ip netns list-id [target-nsid POSITIVE-INT] [nsid POSITIVE-INT] - list network namespace ids",
                    "content": ""
                },
                {
                    "name": "(nsid)",
                    "content": "Network namespace ids are used to identify a peer network namespace. This command dis‐\nplays nsids of the current network namespace and provides the corresponding iproute2\nnetns name (from /run/netns) if any.\n\nThe target-nsid option enables to display nsids of the specified network namespace in‐\nstead of the current network namespace. This target-nsid is a nsid from the current\nnetwork namespace.\n\nThe nsid option enables to display only this nsid. It is a nsid from the current net‐\nwork namespace. In combination with the target-nsid option, it enables to convert a\nspecific nsid from the current network namespace to a nsid of the target-nsid network\nnamespace.\n\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "ip netns list\nShows the list of current named network namespaces\n\nip netns add vpn\nCreates a network namespace and names it vpn\n\nip netns exec vpn ip link set lo up\nBring up the loopback interface in the vpn network namespace.\n\nip netns add foo\nip netns add bar\nip netns set foo 12\nip netns set bar 13\nip -n foo netns set foo 22\nip -n foo netns set bar 23\nip -n bar netns set foo 32\nip -n bar netns set bar 33\nip netns list-id target-nsid 12\nShows the list of nsids from the network namespace foo.\nip netns list-id target-nsid 12 nsid 13\nGet nsid of bar from the network namespace foo (result is 23).\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ip(8)\n\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Original Manpage by Eric W. Biederman\nManpage revised by Nicolas Dichtel <nicolas.dichtel@6wind.com>\n\n\n\niproute2                                     16 Jan 2013                                 IP-NETNS(8)",
            "subsections": []
        }
    },
    "summary": "ip-netns - process network namespace management",
    "flags": [],
    "examples": [
        "ip netns list",
        "Shows the list of current named network namespaces",
        "ip netns add vpn",
        "Creates a network namespace and names it vpn",
        "ip netns exec vpn ip link set lo up",
        "Bring up the loopback interface in the vpn network namespace.",
        "ip netns add foo",
        "ip netns add bar",
        "ip netns set foo 12",
        "ip netns set bar 13",
        "ip -n foo netns set foo 22",
        "ip -n foo netns set bar 23",
        "ip -n bar netns set foo 32",
        "ip -n bar netns set bar 33",
        "ip netns list-id target-nsid 12",
        "Shows the list of nsids from the network namespace foo.",
        "ip netns list-id target-nsid 12 nsid 13",
        "Get nsid of bar from the network namespace foo (result is 23)."
    ],
    "see_also": [
        {
            "name": "ip",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/ip/8/json"
        }
    ]
}