# iwd+dhcpcd take 3 minutes to acquire ip address

## smartding

I'm working in a wifi only environment with dhcp, and I have a Ethernet card with no network cable plugged in.

I'm using iwd+dhcpcd to manage my network. I've added both iwd and dhcpced to default run level as suggested by the iwd wiki: https://wiki.gentoo.org/wiki/Iwd#dhcpcd, and rc-status shows both service have started.

It can take around 3 minutes for iwd+dhcpcd to acquire an ip address for wlan0. Although after that, the network works flawlessly.

I wonder if I can reduce the 3 minutes' waiting. Is dhcpcd trying to acquire ip address for the unplugged eth0?

The dmeg shows

```

[  166.159100] wlan0: authenticate with 32:0d:9e:87:b3:5b

[  166.179272] wlan0: send auth to 32:0d:9e:87:b3:5b (try 1/3)

[  166.283867] wlan0: send auth to 32:0d:9e:87:b3:5b (try 2/3)

[  166.286815] wlan0: authenticated

[  166.287716] wlan0: associate with 32:0d:9e:87:b3:5b (try 1/3)

[  166.294255] wlan0: RX AssocResp from 32:0d:9e:87:b3:5b (capab=0x1c31 status=0 aid=11)

[  166.294514] wlan0: associated

[  166.321043] wlan0: Limiting TX power to 27 (27 - 0) dBm as advertised by 32:0d:9e:87:b3:5b

[  166.409665] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

```

Does the 166 in square bracket mean the number of seconds since boot? 

BTW, I added the "net.ifnames=0" to GRUB_CMDLINE_LINUX, so my network interface is wlan0 intead of wl*

----------

## OmamoriIchika

Did you add both iwd and dhcpcd in runlevel? If you do, it may cause some problem.

----------

## smartding

 *OmamoriIchika wrote:*   

> Did you add both iwd and dhcpcd in runlevel? If you do, it may cause some problem.

 

The gentoo wiki https://wiki.gentoo.org/wiki/Iwd#dhcpcd suggests I should add both the dhcpcd and then iwd service to the default runlevel

----------

## NeddySeagoon

smartding,

```
[  166.159100]
```

is the time since kernel system time started.

That's shortly after boot.

That's a detail that mostly doesn't matter, unless you have problems before kernel system time is started.

Your wifi becomes ready in about 0.250 sec. 

What takes up the 166 sec before that?

Please put all of dmesg onto a pastebin so we can see where the time goes.

I suspect its timeouts waiting for firmware loading, or something like that.

----------

## smartding

 *NeddySeagoon wrote:*   

> smartding,
> 
> ```
> [  166.159100]
> ```
> ...

 

Thank you for your reply, here's the whole dmesg:

https://pastebin.com/raw/0mRdVBdW

----------

## NeddySeagoon

smartding,

```
[    6.678490] caller _nv000707rm+0x1af/0x200 [nvidia] mapping multiple BARs

[  165.927273] wlan0: authenticate with 32:0d:9e:87:b3:5b
```

The problem is here, what is happening it that huge gap ?

The is another oddity. That's the first entry in dmesg for wlan0

Normally there is driver initialisation and sometimes firmware loading. Those entries are missing. 

Its something like

```
 [    0.331037] r8169 0000:04:00.0 eth0: RTL8168g/8111g, 
```

but for wlan0.

What Wifi device do you have and how is is connected?

It should either be is 

```
lspci -nnk
```

 or in 

```
lsusb
```

----------

## smartding

 *NeddySeagoon wrote:*   

> smartding,
> 
> ```
> [    6.678490] caller _nv000707rm+0x1af/0x200 [nvidia] mapping multiple BARs
> 
> ...

 

lspci -k shows I have the following wifi card:

```

   03:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8723BE PCIe Wireless Network Adapter

   Subsystem: Lenovo Device b728

   Kernel driver in use: rtl8723be

```

I've compiled the rtl8723be driver as a kernel module: CONFIG_RTL8723BE=m

And I have installed the sys-kernel/linux-firmware package

----------

## NeddySeagoon

smartding,

```
[    1.497039] rtl8723be 0000:03:00.0: enabling device (0000 -> 0003)

...

[    1.512964] rtl8723be: Using firmware rtlwifi/rtl8723befw_36.bin

[    1.513606] ieee80211 phy0: Selected rate control algorithm 'rtl_rc'

[    1.513890] rtlwifi: rtlwifi: wireless switch is on
```

That's here but there is no wlan0 device.

That's after 

```
[    0.659835] EXT4-fs (sda4): mounted filesystem with ordered data mode. Opts: (null)

[    0.660529] VFS: Mounted root (ext4 filesystem) readonly on device 8:4.
```

That after root is mounted.

```
[  165.927273] wlan0: authenticate with 32:0d:9e:87:b3:5b

[  165.947463] wlan0: send auth to 32:0d:9e:87:b3:5b (try 1/3)

[  166.054874] wlan0: send auth to 32:0d:9e:87:b3:5b (try 2/3)

[  166.062498] wlan0: authenticated

[  166.062808] wlan0: associate with 32:0d:9e:87:b3:5b (try 1/3)

[  166.069155] wlan0: RX AssocResp from 32:0d:9e:87:b3:5b (capab=0x1c31 status=0 aid=14)

[  166.069407] wlan0: associated
```

Is all required before dhcp can do its thing.

There are two questions, where is the wlan0 annoucement?

How do you start wlan0?

```
[  165.927273] wlan0: authenticate with 32:0d:9e:87:b3:5b
```

is the start of that process. What happens before it?

-- edit --

If you use OpenRC, edit /etc/rc.conf to enable logging 

```
# rc_logger launches a logging daemon to log the entire rc process to

# /var/log/rc.log

# NOTE: Linux systems require the devfs service to be started before

# logging can take place and as such cannot log the sysinit runlevel.

#rc_logger="YES"
```

reboot and pastebin the log.

----------

## smartding

NeddySeagoon

I don't have the computer with me at the moment, I will post the log tomorrow.

But I have another laptop, which can acquire IP address very fast, no 3 minutes' delay.

It has a Qualcomm Atheros QCA6174 802.11ac Wireless Network Adapter.

As a comparison, I ran dmesg | grep wlan0, it shows

```

[    4.823867] wlan0: authenticate with 24:7e:51:eb:7f:70

[    4.891488] wlan0: send auth to 24:7e:51:eb:7f:70 (try 1/3)

[    4.893149] wlan0: authenticated

[    4.893959] wlan0: associate with 24:7e:51:eb:7f:70 (try 1/3)

[    4.897791] wlan0: RX AssocResp from 24:7e:51:eb:7f:70 (capab=0x431 status=0 aid=8)

[    4.900194] wlan0: associated

[    5.880385] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

```

We can see that it also begins with wlan0: authenticate with 24:7e:51:eb:7f:70, nothing before that.

----------

## NeddySeagoon

smartding,

Your 

```
[    4.823867] wlan0: authenticate with 24:7e:51:eb:7f:70

[    4.891488] wlan0: send auth to 24:7e:51:eb:7f:70 (try 1/3)

[    4.893149] wlan0: authenticated

[    4.893959] wlan0: associate with 24:7e:51:eb:7f:70 (try 1/3)

[    4.897791] wlan0: RX AssocResp from 24:7e:51:eb:7f:70 (capab=0x431 status=0 aid=8)

[    4.900194] wlan0: associated

[    5.880385] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready 
```

That's the Wifi becoming authenticated then associated, so that the radio link is ready. That has to happen before dhcpcd can ask for an IP address.

It effect, once authentication and association are complete, the interface can be used as if it was wired.

What starts wlan0 here and why does it run sooner?

It would be useful to compare the two.

----------

## smartding

 *NeddySeagoon wrote:*   

> smartding,
> 
> ```
> [    1.497039] rtl8723be 0000:03:00.0: enabling device (0000 -> 0003)
> 
> ...

 

Here's my OpenRC log: https://pastebin.com/raw/LjJnFTLz

This time I waited like 10 minutes, still no ip address, then I manually ran "iwctl station wlan0 scan" 2-3 times, and I have an IP address!

There's the output of "dmesg | grep wlan"

```

[  615.922865] wlan0: authenticate with 32:0d:9e:87:b3:5b

[  615.943057] wlan0: send auth to 32:0d:9e:87:b3:5b (try 1/3)

[  615.945748] wlan0: authenticated

[  615.946483] wlan0: associate with 32:0d:9e:87:b3:5b (try 1/3)

[  615.952573] wlan0: RX AssocResp from 32:0d:9e:87:b3:5b (capab=0x1c31 status=0 aid=20)

[  615.952827] wlan0: associated

[  616.066022] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

[  619.210957] wlan0: Limiting TX power to 27 (27 - 0) dBm as advertised by 32:0d:9e:87:b3:5b

```

Here's the complete dmesg: https://pastebin.com/raw/5pV6e8v3

Is wlan0's authentication and association triggered by iwd's scan command? I don't have anything in /etc/iwd/main.conf that disables iwd's automatic periodic scan. So why wasn't iwd scanning earlier? 

BTW, I booted the computer with archlinux, there's no delay when acquiring IP address. So there's nothing wrong with the hardware.

----------

## halcon

Hi smartding,

I've been using iwd + dhcpcd on my laptop for more than a year. But I haven't added them to any runlevels, I always start them manually (because I also connect the laptop to a wired network).

I think your issue may be related to that the desired wifi network is not found for these minutes (it happens to me too). Please try (by user)

```
$ iwctl adapter list

$ iwctl station list

$ iwctl station wlan0 scan

$ iwctl station wlan0 get-networks
```

If there is no the desired wifi network in the output of the last command, than my guess is right.

----------

## smartding

 *halcon wrote:*   

> Hi smartding,
> 
> I've been using iwd + dhcpcd on my laptop for more than a year. But I haven't added them to any runlevels, I always start them manually (because I also connect the laptop to a wired network).
> 
> I think your issue may be related to that the desired wifi network is not found for these minutes (it happens to me too). Please try (by user)
> ...

 

Thanks for sharing your experience.

The 3-10 minutes' delay is unlikely due to the wifi network being unavailable. Because every time I run "iwctl station wlan0 scan", I can always find it.

----------

## UberLord

 *halcon wrote:*   

> I've been using iwd + dhcpcd on my laptop for more than a year. But I haven't added them to any runlevels, I always start them manually (because I also connect the laptop to a wired network).

 

dhcpcd will automatically prefer wired over wireless and swap between the two mostly seamlessly on Linux, so adding dhcpcd to the default runlevel is fine.

It's designed so that it should just be plug and play.

----------

## halcon

Hi Uberlord,

 *UberLord wrote:*   

> dhcpcd will automatically prefer wired over wireless and swap between the two mostly seamlessly on Linux, so adding dhcpcd to the default runlevel is fine.
> 
> It's designed so that it should just be plug and play.

 

"Just plug and play" and "swap between the two mostly seamlessly" is not that I need.

 *halcon wrote:*   

> because I also connect the laptop to a wired network

 

Evidently, I haven't expressed myself clearly. I didn't mean that I connect to both networks at the same time. I connect the laptop or to wireless, or to wired. In wireless, I get IP automatically via dhcpcd. In wired, I get a static IP via netifrc. So, I don't add dhcpcd to any runlevel and start it manually after connecting to wireless. Simple.

----------

## UberLord

 *halcon wrote:*   

> Evidently, I haven't expressed myself clearly. I didn't mean that I connect to both networks at the same time. I connect the laptop or to wireless, or to wired. In wireless, I get IP automatically via dhcpcd. In wired, I get a static IP via netifrc. So, I don't add dhcpcd to any runlevel and start it manually after connecting to wireless. Simple.

 

So I like to use one tool for the job, keeping it simple.

While dhcpcd won't setup bridging for example, it can setup static IP when you plug the cable in and remove it when you unplug.

You don't need netifrc for that.

```

# /etc/dhcpcd.conf

interface eth0

    static ip_address=192.168.1.101/24

    static routers=192.168.1.1

    static domain_name_servers=192.168.1.1

```

But let me also be clear - you always have the freedom to setup your system how you like, I am just highlighting a way of hopefully making it simpler.

----------

## halcon

 *UberLord wrote:*   

> 
> 
> ```
> # /etc/dhcpcd.conf
> 
> ...

 

Thank you for this example. I'll keep it in mind.

 *UberLord wrote:*   

> So I like to use one tool for the job, keeping it simple.
> 
> While dhcpcd won't setup bridging for example, it can setup static IP when you plug the cable in and remove it when you unplug.
> 
> You don't need netifrc for that.

 

From this point of view, one tool would be simpler, yes. But I think of netifrc not as a (additional) tool, but as a part of the (base) system  :Smile: 

 *UberLord wrote:*   

> But let me also be clear - you always have the freedom to setup your system how you like, I am just highlighting a way of hopefully making it simpler

 

Sure, I realized that! It's useful to hear opinions of others. Sometimes I find out that I haven't been aware of something important for a long time. For example, I didn't know about existence /usr/src/linux/scripts/diffconfig  :Smile: 

----------

