0

I'm using an RPI3B+ to learn about dhcp servers. I've hit a snag I can't figure out. Please bear with me. I want to explain what's happening in detail so you can understand it better.

I booted my pi with a fresh install of Raspi-lite. The pi was not connected to my network switch at the time. I configured everything in raspi-config, including the wifi.

I ran ip addr show. The lan interface, enxb827ebcgfa21, had no ip address (as expected) and the wlan0 interface had an IP address from the wireless router of 192.168.1.205/24. The settings of the wireless router are something on the order of:

IP 192.168.1.254
Gateway 192.168.1.1
DNS 8.8.8.8  192.168.1.1
IP range is 192.168.2 - 254

It also connect to the internet and a DHCP server is running on it. There is no other DHCP server running on the subnet. The only other computer connected to my switch is my Window desktop.

I could ping google.com so I knew the wifi was working.

Now I went to set a static ip address. I edited the /etc/dhcpcd.conf like this:

interface enxb827ebc6fa21
static ip_address=192.168.1.7/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 192.168.1.1

Nothing elaborate. I then edited my wpa_supplicant file like this:

Network={
    ssid=’my_network_name’
    psk=’my_network_password
}

After I rebooted I ran ip addr show again. The enxbxxxxx interface had picked up the static ip address from the dhcpcd.conf file. And the wlan0 still had the same ip address it picked up from the router the first time and still connected to the internet. Everything looked good.

But then I rebooted and connected the pi to my switch. This time, the lan interface still had the static IP from the dhcpcd.conf file. But the wlan0 interface no longer had an address and would no longer connect to the internet. Only Unplugging the ethernet cable and rebooting doesn't help.

I went back to the dhcpcd.conf file, removed my static ip changes and rebooted. This time the lan IP address was an odd 169.254.225/16. The wlan0 still had no IP address and still wouldn’t connect to the internet. Only reverting settings in dhcpcd.conf helps.

  1. So why does the wlan0 interface stop working after a static ip address is set and the switch is connected? What's causing that to happen.
  2. Where is this 169.254 IP address coming from? It’s not from the router so it must be coming from the OS, but where?

Thanks in advance.

Ingo
  • 42,961
  • 20
  • 87
  • 207

2 Answers2

1

It is difficult to completely understand your network environment because lack of answers to my questions (where is the switch connected, what has 192.168.1.1). So I can only give general information about how DHCP is working but it may help you to find what's going wrong with your setup.

There are mainly three ways to give an interface an ip address in this priority:

  1. setup static ip address will overwrite any other settings
  2. getting an ip address from a DHCP server on the network
  3. autoconfigure a link-local address if nothing others is used

When using a static ip address and a DHCP server is also running on the network you should ensure that the ip address is outside the range that the DHCP server will give to devices. The DHCP server may check this conflict by pinging the address and avoid to give the same ip address from its pool to another device. But this only works if the conflicting device is just online. More detailed answers to this feature you will find at Does dhcpcd prevent a remote DHCP server serving an IP address that is declared static?. You are always on the save side if you use a static ip address outside the pool from the DHCP server. The pool on your DHCP server is set from 192.168.1.2 to 192.168.1.254 (I guess because you write IP range is 192.168.2 - 254). You should set it for example from 192.168.1.128 to 192.168.1.253 (192.168.1.254 is used for the wifi router itself).

If a device has DHCP lookup enabled and it does not have an ip address it will broadcast into the subnet it is connected to and request for an address. You have to ensure that only one DHCP server is running on your broadcast domain (subnet without router connection). Otherwise each DHCP server will response to a request from a device with a different ip address from its different pool. It is obvious that this cannot work.

If the interface does not have a static ip address and if it does not find a DHCP server on the subnet it is connected to then the avahi daemon will give it an ip address from the reserved ip address block 169.254.0.0/16 (Link-local addresses). This are 65536 ip addresses. avahi ensures that the ip address it gives to the interface will be unique on the broadcast domain. If you use a static ip address from this address block you violate specification. Never do it. Link-local addresses work ad hoc on (small) networks without a DHCP server. avahi will also give a DNS name to the ip address from the also reserved DNS domain .local, for example raspberrypi.local.

Ingo
  • 42,961
  • 20
  • 87
  • 207
0

See How to set up networking/WiFi and How to set up Static IP Address

List the full contents of /etc/dhcpcd.conf and /etc/wpa_supplicant/wpa_supplicant.conf (you can obscure the values of SSID & psk)

169.254 is a Link-local address

Milliways
  • 62,573
  • 32
  • 113
  • 225