Unix & Linux Asked by Jorje12 on December 17, 2021
I have a project in which a user can change the RPI’s networking settings via a Web Interface from the following:
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:
# 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 ?
# 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.
You can't use fallback
to switch between different interfaces (which seems the goal in case 2). The dhcp fallback profile is used on the interface for which it was configured if the dhpc on this same interface fails, not if the dhcp on another interface fails.
Not sure if it is possible to use arping
for such purpose (see dhcpd.conf). Idea would be to ping the first interface and point to a profile with "no ip". The alternative MAC address profile would then contain the static IP or DHCP to be used on the secondary interface. But I'm afraid that this will not work reliable since it depends on the timing of when the primary interface will get up with an IP address.
Answered by palto on December 17, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP