1

OS: Raspberry Buster Lite

Board: Raspberry Pi 4

I have been playing with dhcpcd.conf for the last few days. I am trying to change the network settings from within a C++ program. The program reads the new network settings from a .txt file and applies them correctly over (overwriting) dhcpcd.conf and wpa_supplicant.conf, respectively. And then it does system("ip link set eth0 down && ip link set eth0 up && ip link set wlan0 down && ip link set wlan0 up");.

The thing is that the interfaces go down and then up but they don't have any IP assigned to them.

This is the current content of dhcpcd.conf:

interface wlan0
hostname PiWiFi
clientid PiWiFi
static ip_address=192.168.1.120/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8
interface eth0
noipv4
noipv6

with wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="MySSID"
psk="Password1234"
}

I have also tried this dhcpcd.conf:

interface wlan0
noipv4
noipv6
interface eth0
hostname PiEth
clientid PiEth
static ip_address=192.168.1.20/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8

with wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

eth0 receives an IP Address ! wlan0 does not.

Also, I have tried disabling the service that runs the C++ program, rebooting the Raspberry and then manually changing dhcpcd.conf and wpa_supplicant.conf and it is the same story. wlan0 won't work.

1 Answer 1

3

To configure the interfaces with ip addresses the dhcpcd.service is used. That's the reason why you set them in /etc/dhcpcd.conf. It seems that only setting the interfaces down and up with ip does not trigger dhcpcd to reconfigure the interfaces. Try to use:

system("systemctl daemon-reload && systemctl restart dhcpcd.service")

of course with root rights.

5
  • But ip link set eth0 down && ip link set eth0 works. So, dhcpcd reconfigures the eth0 interface. Why isn't wlan0 working ?
    – bleah1
    Commented Sep 24, 2019 at 8:07
  • Also, systemctl daemon-reload && systemctl restart dhcpcd.service with root rights had no effect. wlan0 still doesnt' have any IP
    – bleah1
    Commented Sep 24, 2019 at 8:17
  • I've went into raspi-config and set a ssid and password and, as expected, wlan0 was assigned a dhcp IP. Then I've went into /etc/dhcpcd.conf and /etc/wpa_supplicant/wpa_supplicant.conf files and the only lines that were added were network={ ssid="MySSID" psk="Password1234" }
    – bleah1
    Commented Sep 24, 2019 at 8:25
  • @bleah1 If everything works on the command line then the problem must be your C++ program. I can't say much about it because I don't know it. Maybe you don't match the correct environment to execute system commands in the invoked shell?
    – Ingo
    Commented Sep 24, 2019 at 9:33
  • I've ended up adding country=" and the country code to wpa_supplicant.conf` and also using system("systemctl daemon-reload && systemctl restart dhcpcd.service") whenever I change the network settings and it works nicely. I don't know which fixed it.
    – bleah1
    Commented Sep 27, 2019 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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