Skip to content

dietpi-network: new tool for multi interface configuration - #8251

Draft
MichaIng with Copilot wants to merge 13 commits into
devfrom
copilot/move-menu-networkadapters-functionality
Draft

dietpi-network: new tool for multi interface configuration#8251
MichaIng with Copilot wants to merge 13 commits into
devfrom
copilot/move-menu-networkadapters-functionality

Conversation

Copilot AI commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

DietPi-Config's Menu_NetworkAdapters hardcoded exactly one Ethernet and one WiFi interface (resolved via G_GET_NET prefix matching), stored everything in a single /etc/network/interfaces, and had no non-interactive way to change settings.

New dietpi/dietpi-network script

  • Extracted Menu_NetworkAdapters/_Ethernet/_Wifi/_Proxy and all exclusive helpers/state out of dietpi-config into a standalone script, structured like dietpi-vpn/dietpi-ddns.
  • dietpi-config now execs /boot/dietpi/dietpi-network where Menu_NetworkAdapters used to be called; all related TARGETMENUID handling is removed.

Per-interface, name-independent configuration

  • Interfaces are enumerated via /sys/class/net/* instead of G_GET_NET: WiFi = has a wireless subdir, Ethernet-like = has a device subdir but no wireless. Works with systemd predictable names (enp3s0, wlp2s0, ...), not just eth*/wlan*.
  • Every detected interface gets its own submenu, so multiple Ethernet and/or WiFi adapters are configurable independently.
  • Added a global WiFi toggle, decoupled from any specific adapter.

Storage moved to per-interface drop-ins

  • Settings are written to /etc/network/interfaces.d/<name>.conf instead of rewriting /etc/network/interfaces wholesale.
  • If an interface is already defined in /etc/network/interfaces, its config is read from there for the submenu; applying settings removes that interface's block from /etc/network/interfaces to avoid duplicate definitions.

New CLI

  • Any submenu can be opened directly: dietpi-network <ifname|proxy|wifi|country|test>.
  • Settings changeable non-interactively, e.g.:
    dietpi-network apply wlan0 --enable --static --hotspot --ip 192.168.42.1 --mask 255.255.255.0
    dietpi-network wifi disable
    dietpi-network proxy address proxy.example.com
    

dietpi-software WiFi Hotspot

  • Install/uninstall now detects the WiFi interface via /sys/class/net/*/wireless and delegates interface configuration to dietpi-network apply ... --hotspot/--client instead of editing /etc/network/interfaces directly.

Other

  • Added dietpi-network shell alias alongside the other DietPi CLI tools.
  • dietpi-set_hardware eth-forcespeed now accepts an explicit interface argument, since multiple Ethernet interfaces can exist.

@MichaIng MichaIng left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Please address my new comments.

Additionally:

  • Add a new CLI option to dietpi-wifidb, to pass an explicit WiFi interface name, replacing the G_GET_NET -t wlan iface call if given. Use that in dietpi-network when called from a particular interface submenu.
  • Migrate Allo_Main in dietpi/func/dietpi-set_software to the new dietpi-network CLI as well. Use G_GET_NET -t eth iface to obtain the interface to apply settings to.
  • Add an additional option to remove an interface configuration entirely, instead of just disabling it.
  • If two interfaces are enabled on the same subnet, they cannot both have the same gateway/default route (unless we implement a metric option), and more importantly, the duplicate LAN routes like 192.168.1.0/24 on two interfaces can cause asymmetric traffic, that way break communication with e.g. a connected SSH client. Until we implement some more complex e.g. routing table based solution for this, it hence needs to be avoided that two interfaces are enabled on the same subnet. Please hence add the following: If another interface does already use the same subnet that is to be applied via static IP, or if an interface is to be enabled with DHCP while a default route is already assigned to another interface, show an additional prompt with this information. Allow to ignore or disable the potentially conflicting interface, to proceed. If the user chooses to disable the conflicting interface, comment out the respective allow-hotplug/auto line, and ifdown --force that interface, before continuing to apply changes/enable the new interface.

Comment thread dietpi/dietpi-network Outdated
Comment thread dietpi/dietpi-software Outdated
Comment thread dietpi/dietpi-network Outdated
Comment thread dietpi/dietpi-network Outdated

Copilot AI commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
Please address my new comments.
...

Addressed all points in ca6012f/9ed570b:

  • dietpi-wifidb now supports -i <iface> to pass an explicit WiFi interface, used from dietpi-network's WiFi submenu instead of relying on auto-detection.
  • Allo_Main in dietpi-set_software now uses G_GET_NET -t eth iface and delegates to dietpi-network apply.
  • Added a "Remove" menu option (and it was already available via CLI remove) to delete an interface's stored configuration entirely, distinct from "Disable".
  • Added Check_Network_Conflicts: when applying static IP/DHCP settings, if another enabled interface already uses the same subnet, or already has a default gateway while enabling DHCP, the interactive menu now shows a warning prompt to either ignore or disable the conflicting interface (commenting out allow-hotplug/auto and ifdown --forceing it) before proceeding; the CLI requires an explicit --force flag to bypass the check.

Copilot AI and others added 7 commits August 17, 2026 14:00
…menus/CLI

Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
…e text

Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
…omment

Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
* remove global WiFi submenu, as it doubles with the options in main menu
* clearify virtual vs hardware vs real interfaces: There are "real" interfaces that we can configure, and that exist independently of definitions in the network config. These are the only ones we list in the menu, and after some testing, this should be the only ones the script accepts as input, probably accepting `--force` to override and apply the config in any case. Among the "real" interfaces, there is WiFi, and everything else is interpreted as Ethernet. This includes virtual interfaces provided from container host to guest, because they can be configured just like any true Ethernet interface, without the need for wpasupplicant, and without a way to set it up with hostapd. True WiFi devices are automatically "real" devices, with `/sys/class/net/*/type == 1`. Remove the "hardware" vs "virtual" differentiation, which does not fit, and is not what is important for us.
* fix lost credentials in proxy export: looks like Copilot passed this through some internal credentials exposure filter or so. But prevent password from being printed to console when stored to dietpi.txt.
* do not attempt to parse /etc/hostapd/hostapd.conf if it does not exist, same with /etc/wpa_supplicant/wpa_supplicant.conf, but print STDERR when parsing fails
* use mktemp for temporary interfaces file
* write per-interface config in one go, after forging the content in a variable, and skip directives which would be added in commented form only
* skip unnecessary `systemctl daemon-reload` when restarting interface
* restore ifup@.service ourput to console while restarting an interface
* do not stop hostapd and DHCP server if the restarted WiFi interface is not a hotspot, since another interface might be. We currently have no option to toggle an interface between hotspot and client mode from within the script. Instead, it needs to be uninstalled via dietpi-software. Also, stopping the services wouldn't be permanent. Moving this from dietpi-software into this script is a goal, but to be done in a separate PR.
* add some input validation to menus, and migrate some from custom validation to G_WHIP_INPUTBOX_REGEX
* treat a missing /etc/hostapd/hostapd.conf as error when settings are applied with an declared interface as hotspot, prompting an error message
* skip conflicting network check entirely if `--force` was passed, hence settings are applied anyway, but otherwise show the respective dialog as well for CLI calls: CLI does not mean non-interactive across DietPi scripts!
* call main menu "Main_Menu" and the menu loop "Menu_Loop"
* remove some redundant NEXT_MENU assignments and further code cleanup and formatting
* dietpi-installer: do not pre-seed interface definitions in main config
* bring down interface before removing its config, otherwise ifdown is doomed to fail
* dietpi-software: WiFi Hotspot: remove WiFi interface configuration when uninstalling the WiFi hotspot, revert Tor Hotspot to use G_GET_NET, and skip redundant `--static` flag, which is implied with `--hotspot`
@MichaIng
MichaIng force-pushed the copilot/move-menu-networkadapters-functionality branch from ba91931 to 6e19c15 Compare August 17, 2026 12:00
@MichaIng MichaIng changed the title Extract network configuration into dietpi-network with per-interface support and CLI dietpi-network: new tool for multi interface configuration Aug 17, 2026
* extend "--force" flag to apply settings as well if the interface does not exist
* detect interfaces named "wlanX" as WiFi interfaces
* align WiFi vs Ethernet detection with G_GET_NET, and remove redundant `[[ $type ]]` check
* dietpi-wifidb: make clear that "-i <iface>" is relevant for network scanning via menu only
* dietpi-firstboot: rework network setup to use dietpi-network CLI
* dietpi-firstboot: do not attempt to being up an interface if it does not exist yet, so that it does not disturb ifup@.service in case/once it is attached/detected
dietpi-set_hardware: eth-forcespeed: abort if no Ethernet interface can be found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants