# dhcp sometimes gives me an APIPA address (169.254.*)

## ultraslinky

Hello fellow Gentoo users  :Smile: 

So my wireless works pretty well i must say. However every, let's say, 20th attempt to connect to any wireless (my home, my university, my friend's home etc., definitely not a router problem) i don't get a proper IP address. I'm getting an APIPA address apparently:

```
Netbukkolo james # rc-service net.wlan0 start

 * Bringing up interface wlan0

 *   Starting wpa_supplicant on wlan0 ...                                                                              [ ok ]

 *   Starting wpa_cli on wlan0 ...                                                                                     [ ok ]

 *   Backgrounding ... ...

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

I have tried with different programs etc:

```
Wicd: Connection failed, unable to get an IP address
```

This is what ifconfig gives me:

```
Netbukkolo james # ifconfig

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 16436  metric 1

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 128  bytes 8064 (7.8 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 128  bytes 8064 (7.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  metric 1

        inet 169.254.70.226  netmask 255.255.0.0  broadcast 169.254.255.255

        inet6 fe80::221:63ff:fef6:923f  prefixlen 64  scopeid 0x20<link>

        ether 00:21:63:f6:92:3f  txqueuelen 1000  (Ethernet)

        RX packets 18  bytes 2736 (2.6 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 127  bytes 22226 (21.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```

And after killing dhcpcd and running it in a terminal:

```
james@Netbukkolo ~ $ sudo dhcpcd wlan0

dhcpcd[2891]: version 5.2.12 starting

dhcpcd[2891]: wlan0: checking for 169.254.85.204

dhcpcd[2891]: wlan0: using IPv4LL address 169.254.85.204

dhcpcd[2891]: forked to background, child pid 2905
```

I have read this from https://forums.gentoo.org/viewtopic-t-911548.html :

```
169.254.* are APIPA addresses which dhcpcd uses when no DHCP server can be reached. Be aware that after dhcpcd gets an APIPA address, it will re-assign it immediately on second launch again, and only change it when a DHCP server replies. 

To see whether you have any connection at all, set a static IP address and try to ping hosts on the local network. Also try to launch wpa_supplicant manually and wait for CTRL_EVENT_CONNECTED.
```

Rebooting gentoo doesn't help, it will keep obtaining that address. I have tried reloading the kernel module but to no avail. However my router's dhcp server is definitely reachable as my cell phone will happily connect to the network, and to solve the problem i have to reboot into Windows (which will connect to the network) and back into Gentoo, then it will give me a proper ip address and internet works. 

The question is: How do i stop getting these APIPA addresses? It's just an annoying issue, i know, but still, i'd be interested  :Smile: 

If it is of any need, my wireless card is: 

```
02:00.0 Ethernet controller: Atheros Communications Inc. AR242x / AR542x Wireless Network Adapter (PCI-Express) (rev 01)

   Subsystem: Askey Computer Corp. Device 7131

   Flags: bus master, fast devsel, latency 0, IRQ 16

   Memory at f0100000 (64-bit, non-prefetchable) [size=64K]

   Capabilities: [40] Power Management version 2

   Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit-

   Capabilities: [60] Express Legacy Endpoint, MSI 00

   Capabilities: [90] MSI-X: Enable- Count=1 Masked-

   Capabilities: [100] Advanced Error Reporting

   Capabilities: [140] Virtual Channel

   Kernel driver in use: ath5k

   Kernel modules: ath5k
```

Thanks to everyone in advance!

-James

----------

## Hu

The exact answer depends on your DHCP client.  Per man dhcpcd section Local Link configuration, it looks like you want --noipv4ll.  This can be passed on the dhcpcd command line via the dhcpcd_eth0 directive in /etc/conf.d/net.

----------

## ultraslinky

Thank you Hu  :Smile:  although i think i need to change the settings for wlan0 and not eth0.

So i could just add ' dhcpcd_wlan0="--noipv4ll" ' in /etc/conf.d/net  ? Is that the correct way of writing a directive? Right now my /etc/conf.d/net file is empty, since it defaults to dhcpcd anyway.

----------

## ultraslinky

Well i just tried adding that entry and then restarting net.wlan0. I checked dhcpcd's arguments with ps -aux. And it does have the correct command line option  :Smile:  net.wlan0 complains "WARNING: net.wlan0 has started, but is inactive". It used to do that when i got assigned an APIPA address. However internet works fine and i have a normal 192.* address. 

Thanks again Hu!

----------

## NeddySeagoon

ultraslinky,

You get a link local IP if dhcp fails to get a 'real' IP for any reason.

Have you set an overly agressive timeout limit in your /etc/conf.d/net file. 

The default is 60 seconds but it only gets to that timeout when something is badly wrong.

----------

## ultraslinky

 *NeddySeagoon wrote:*   

> ultraslinky,
> 
> You get a link local IP if dhcp fails to get a 'real' IP for any reason.
> 
> Have you set an overly agressive timeout limit in your /etc/conf.d/net file. 
> ...

 

Hey NeddySeagoon,

Yeah, i have read the manual about those ipv4ll addresses.

My /etc/conf.d/net file is empty (since it defaults to dhcpcd and i don't need anything else), i just added 'dhcpcd_wlan0="--noipv4ll"'.

However i don't get this "timeout". When i get assigned one of those 169.* addresses, it does so immediately. From the time I invoke dhcpcd to dhcpcd obtaining an 169.* address takes maybe a second, not any more.

----------

