Skip to main content

linux - How to move wireless connection to other network namespace?


# ip link set  wlan0 netns 1
RTNETLINK answers: Invalid argument

It works for usual ethernet. It also works for proprietary broadcom "wl" driver.


How to do it for usual mac80211-based driver?



Answer



You need to move the PHY:


iw phy phy0 set netns 666

Where 666 is the pid of some process running in that network namespace; for netspaces created by iproute2 tools (with ip netns), you can create a short-lived process in there and get its pid:


iw phy phy0 set netns "$(ip netns exec mynetns sh -c '
sleep 1 >&- & echo "$!"')"

To move it back to the root namespace:


ip netns exec mynetns iw phy phy0 set netns 1

Comments