I have a project in which a user can change the RPI's networking settings via a Web Interface from the following:
- DHCP WiFi
- DHCP Ethernet
- Static WiFi
- Static Ethernet
Each choice re-configures dhcpcd_conf
and wpa_conf
accordingly. It works perfectly nice.
The whole package is designed to be in DHCP Ethernet on the first boot. But this design has a flaw in it because not every user has a DHCP server in place.
That's when I thought of making a fallback static Ethernet IP and this is what I came up with:
Case 1 - DHCP Ethernet
# dhcpcd_conf
interface wlan0
noipv4
noipv6
interface eth0
hostname DeviceEth
clientid
profile static_eth0
static ip_address=192.168.1.150/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8
interface eth0
fallback static_eth0
# wpa_conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
As you can see I set wlan0
to have no IP, then I set eth0
to DHCP and then I set the same eth0
to a fallback profile
.
Is this correct ? Can I have two different settings on the same interface ?
Case 2 - DHCP WiFi:
# dhcpcd_conf
interface wlan0
hostname DeviceWiFi
clientid
interface eth0
noipv4
noipv6
profile static_eth0
static ip_address=192.168.1.150/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8
interface eth0
fallback static_eth0
# wpa_conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=RO
network={
ssid="SSID"
psk="password"
}
Here I set wlan0
to DHCP, then I set eth0
to no ip and then I set the same eth0
to a fallback profile
.
Is this configuration correct ?
In both cases I want only one interface active, that's why I configure one to DHCP and the other one to no IP.
In the case of DHCP WiFi it doesn't matter if wlan0
stays up after the fallback is in effect, because the user will most probably configure a static IP once he reaches the Web Interface and static configuration is similar to the DHCP configuration in the way that it only leaves one interface active at a time.
fallback
option you can configure a static IP for an interface in case it doesn't get an IP address, which seem to be what you try to achieve in case 1. But case 2 is not clear to me, as you seem to try to configure a static IP on eth0 if the DHCP for the wlan0 fails. Why can't eth0 have a permanent static IP in case 2? If it's not connected, then it will be down and the static IP doesn't matter. Maybe you can add some more description about the desired behaviour and why you want such behaviour.wlan0
and keepeth0
disabled or go with your solutionWhy can't eth0 have a permanent static IP in case 2? If it's not connected, then it will be down and the static IP doesn't matter.
But is it possible to make if conditions insidedhcpcd
? I couldn't find any examples online. Basically, what I want is to only have one interface enabled at a time, with a fallback in case DHCP doesn't work. These devices will be outdoor and I don't want them to be easily hack-able.