0

I'm trying to move wlan0 interface to separate namespace (wlan0).

iw phy phy0 set netns name wlan0

unfortunately, after such move I'm not able to bring it up.

Bellow command do nothing:

ip netns exec wlan0 ip link set wlan0 up

Some logs below:

# ip netns exec wlan0 ip a
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:2f:e8:f1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.234/24 scope global wlan0
       valid_lft forever preferred_lft forever

# ip netns exec wlan0 iwconfig
wlan0     IEEE 802.11  ESSID:off/any
          Mode:Managed  Access Point: Not-Associated   Tx-Power=31 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on

lo        no wireless extensions.


# dmesg | grep wlan0
[    5.481627] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[    6.900705] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[ 3989.043318] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[ 6458.760215] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[332124.119807] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready


# ip netns exec wlan0 ip route
default via 192.168.0.1 dev wlan0 linkdown
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.234 linkdown
1

I don't know for what you need to use Linux Network Namespaces. But it seems you are confusing the name of the namespace with the interface name wlan0. I get this if I try:

rpi ~$ sudo -Es
rpi ~# iw phy phy0 set netns name wlan0
Invalid parameter: nsname(name)
Usage:  iw [options] phy <phyname> set netns { <pid> | name <nsname> }

Put this wireless device into a different network namespace:
    <pid>    - change network namespace by process id
    <nsname> - change network namespace by name from /run/netns
               or by absolute path (man ip-netns)

I'm wondering about you don't get this error message. It means wlan0 isn't a valid namespace. You have first to define a namespace before you can add something to it. To not get confused and for clarification I will name my namespace myns and create it with:

rpi ~# ip netns add myns
rpi ~# ip netns list
myns
rpi ~#

Now I move phy0 to the new namespace:

rpi ~# iw phy phy0 set netns name myns
rpi ~# iw list
rpi ~#

As you see there is no longer a device in the default namespace. Instead you will find it in myns:

rpi ~# ip netns exec myns iw list
Wiphy phy0
        max # scan SSIDs: 10
        max scan IEs length: 2048 bytes
[--snip--]

Now from that device you can manage its interface wlan0:

rpi ~# ip netns exec myns ip addr add 192.168.10.20/24 dev wlan0
rpi ~# ip netns exec myns ip link set wlan0 up
rpi ~# ip netns exec myns ip addr show
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether b8:27:eb:06:e8:8b brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.20/24 scope global wlan0
       valid_lft forever preferred_lft forever
rpi ~# exit
exit
rpi ~$

This in short how to use it. As you see with wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> the interface is UP. It only does have NO-CARRIER so only is state DOWN. You have to configure wpa_supplicant in namespace myns to give the interface a carrier and set it's state UP maybe something like:

rpi ~$ sudo ip netns exec myns /sbin/wpa_supplicant -B -c/etc/wpa_supplicant/wpa_supplicant-wlan0.conf -Dnl80211,wext -iwlan0

But I don't know because I haven't tested it. Further configuration in the Network Namespace myns is out of scope here because it doesn't natively belong to Raspberry Pi.

  • I set namespace to wlan0 and put inside interface wlan0 intentionally. But as you can see on your example interface is DOWN, so you are able to reproduce issues. – itiic Jan 22 at 11:31
  • 1
    @itiic I have updated my answer in the last paragraph. – Ingo Jan 22 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.