# wpa_supplicant weird behaviour not honoring net.wlan0

## abduct

I am playing with wpa_supplicant after setting it up according to the wiki, but there are a few things that seem to go wrong that I have to manually correct.

For instance on boot wpa_supplicant is started with these flags:

```
# ps aux | grep wpa

/usr/sbin/wpa_supplicant -B -M -c/etc/wpa_supplicant/wpa_supplicant.conf -B -c/etc/wpa_supplicant/wpa_supplicant.conf -iwlan0
```

and when I use wpa_cli to setup and enable a network the wlan0 interface connects and authenticates, but does not retrieve an IP address.

I have to run 

```

 # rc-service net.wlan0 restart

 * Bringing up interface wlan0

 *   Starting wpa_supplicant on wlan0 ...

Successfully initialized wpa_supplicant

ctrl_iface exists and seems to be in use - cannot override it

Delete '/var/run/wpa_supplicant/wlan0' manually if it is not used anymore

Failed to initialize control interface 'DIR=/var/run/wpa_supplicant GROUP=wheel'.

You may have another wpa_supplicant process already running or the file was

left by an unclean termination of wpa_supplicant in which case you will need

to manually remove this file before starting wpa_supplicant again.

nl80211: deinit ifname=wlan0 disabled_11b_rates=0

 *   start-stop-daemon: failed to start `/usr/sbin/wpa_supplicant'                                                                                                                                                                     [ !! ]

 * ERROR: net.wlan0 failed to start

# killall wpa_supplicant

# rc-service net.wlan0 restart

 * Bringing up interface wlan0

 *   Starting wpa_supplicant on wlan0 ...

Successfully initialized wpa_supplicant                                                                                                                                                                                                [ ok ]

 *   Starting wpa_cli on wlan0 ...                                                                                                                                                                                                     [ ok ]

 *   Backgrounding ... ...

 * WARNING: net.wlan0 has started, but is inactive

```

in order for the service to restart properly and allow the interface to obtain an IP address.

After the above the wpa_supplicant is started as 

```
]# ps aux | grep wpa

/usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -W -B -i wlan0 -P /run/wpa_supplicant-wlan0.pid

/usr/bin/wpa_cli -a /etc/wpa_supplicant/wpa_cli.sh -p /var/run/wpa_supplicant -i wlan0 -P /run/wpa_cli-wlan0.pid -B

```

So here are a few questions:

-Why does the wiki specify the -M options in /etc/conf.d/wpa_supplicant? `man wpa_supplicant' does not list this option at all. What does it even do?

-How can I remove this weird auto startup of wpa_supplicant and use only the net.wlan0 service?  I have the net.wlan0 rc set to run at the default run level along with net.eth0. I have a feeling the net.wlan0 service is launching some kind of dhcp service along side wpa_supplicant/wpa_cli where as what ever is starting the wpa_supplicant daemon first is not.

Here are my current configs for wpa_supplicant:

```
 # cat /etc/conf.d/wpa_supplicant

# conf.d file for wpa_supplicant

#

# Please check man 8 wpa_supplicant for more information about the options

# wpa_supplicant accepts.

#

wpa_supplicant_args="-B -M -c/etc/wpa_supplicant/wpa_supplicant.conf"

```

```
# cat /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel

update_config=1

network={

        ssid="ssid"

        psk="passphrase"

}

```

Thanks for any information

----------

## khayyam

 *abduct wrote:*   

> 
> 
> ```
>  # rc-service net.wlan0 restart
> 
> ...

 

abduct ... you have wpa_supplicant and net.wlan0 in the runlevel (hence there being a cntl_interface in existance on initalisation), you should only have net.wlan0, it will start wpa_supplicant (if configured to do so via 'modules_wlan0='). Note that the configuration /etc/conf.d/wpa_supplicant is only used by wpa_supplicant (the service) and so you should configure via /etc/conf.d/net, eg:

```
modules_wlan0="wpa_supplicant dhcpcd"

wpa_supplicant_wlan0="-Dnl80211 -qq"

config_wlan0="dhcp"
```

Also, why start both the wired and the wireless interface?

HTH & best ... khay

----------

## abduct

@khayyam

Thanks for that, I didn't notice that wpa_supplicant was in the default runlevel for some reason. I've also corrected my /etc/conf.d/net to include a few more options.

I will reboot and check to see all is well after my updates are done.

As for starting both wired and wireless services, I use both on my laptop depending on where I am. I prefer to use wired over wireless when ever it is convenient for me.

Is this a bad thing?

----------

## khayyam

 *abduct wrote:*   

> As for starting both wired and wireless services, I use both on my laptop depending on where I am. I prefer to use wired over wireless when ever it is convenient for me. Is this a bad thing?

 

abduct ... it can be, and so you're best to use 'plug' (via sys-apps/ifplugd, or sys-apps/netplug), eg:

```
modules_eth0="plug dhcpcd"

modules_wlan0="plug wpa_supplicant dhcpcd"
```

This would then bring up the wired interface/service based on cable connection, switching to wireless when disconnected.

HTH & best ... khay

----------

## UberLord

Another approach, and quite a lot easier, is to avoid using net.* and just add wpa_supplicant and dhcpcd to the default runlevels.

Configure wpa_supplicant to run for the interfaces you want, optionally using the -M directive to allow for pluggable wireless interfaces.

/etc/conf.d/wpa_supplicant

```
wpa_supplicant_args="-M"
```

dhcpcd will then react when wireless and wired become available and will prefer the wired connection through using route metrics.

The stock dhcpcd config works fine for this.

See the wiki for more complete details:

https://wiki.gentoo.org/wiki/Wpa_supplicant

----------

