Skip to content

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

Merged
MichaIng merged 24 commits into
devfrom
copilot/move-menu-networkadapters-functionality
Aug 23, 2026
Merged

dietpi-network: new tool for multi interface configuration#8251
MichaIng merged 24 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
@MichaIng MichaIng linked an issue Aug 15, 2026 that may be closed by this pull request

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 requested a review from MichaIng August 15, 2026 23:02
@MichaIng MichaIng linked an issue Aug 15, 2026 that may be closed by this pull request
@MichaIng MichaIng linked an issue Aug 15, 2026 that may be closed by this pull request
@MichaIng
MichaIng force-pushed the copilot/move-menu-networkadapters-functionality branch 2 times, most recently 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
@MichaIng
MichaIng force-pushed the copilot/move-menu-networkadapters-functionality branch 5 times, most recently from c8f8584 to 36e7cd9 Compare August 20, 2026 20:08
@MichaIng
MichaIng marked this pull request as ready for review August 20, 2026 20:28

@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.

So far so good. Works well now as far as I tested. But surely needs more testing.

I am considering to open an early beta for this.

And 1st run setups with new images need to be tested, also with the DHCP => static auto-conversion.

@JappeHallunken JappeHallunken left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I just did a quick test in a VM.

Copilot AI and others added 22 commits August 23, 2026 03:48
…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`
* 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
* dietpi-software: use dietpi-network CLI to apply DHCP assigned IP as static IP (if requested)
* dietpi-software: add NanoPi R3S and Zero2 as headless devices, to disable getty@tty1.service
* dietpi-set_hardware: keyboard: apply "setupcon --save-only" separately first, before applying the change with "setupcon". Otherwise it throws 4 warnings as of the outdated cache, it seems.
* dietpi-set_hardware: apply some comment header above every CLI command's function block, with the literal command name inside, so make searching in the script easier
* dietpi-firstboot: gate all setup steps which depend on a certain package by the fact whether this package is installed, and remove now obsolete hardware ID gates
* dietpi-firstboot: add some info messages about what is done
* remove test CLI commands: G_CHECK_URL can be used directly. This is mainly relevant during interactive setup, where the result is shown in the main menu.
* some CLI help text reorder and alignment
* remove redundant CURRENT_IFACE_MODE_TARGET variable, use CURRENT_IFACE_MODE instead, which was an unused duplicate before
* detect "allow-auto" as well, which is a valid alias for "auto"
* move "Auto Reconnect" to "Additional Options" as it should not be that prominent => mostly needed for mobile devices, not so much for flaky WiFi signal
* add WiFi Hotspot uninstall entry as equivalent to "Remove" for the hotspot
"ip" prints e.g. for veth and VLAN interfaces, but it is not part of the actual interface name, hence does not match `/sys/class/net/*` and would fail other commands like `ifup`.

Align condition that `/sys/class/net/*` needs to be a directory.
* use CIDR notation for CURRENT_IFACE_IP placeholder value, to indicate what is expected, and match what `ip a` prints when assigning live values
* simplify awk script to parse configs, using clarer regex and hardened pattern checks
* Some minor code format enhancements
AUTO_SETUP_NET_STATIC_MASK now superseded by optional CIDR notation with AUTO_SETUP_NET_STATIC_IP
* while nagivating the interface menu, do not override change settings from values in config files, until settings are applied, or the interface menu is exited
* remove redundant MENU_TARGET variable, use NEXT_MENU directly
* rename ENTRY_TARGET => ENTRY_MENU
* Bring up Ethernet interfaces before calling ethtool to parse supported link speeds. This is needed e.g. for the RK35xx 2.5 Mbit PCIe ports, where ethtool throws errors if the interface is down.
* If supported link speeds cannot be parsed, e.g. in case of bridged VirtIO adapters, offer 10/100/1000/2500 Mbits in the menu, along with a warning that obtaining supported speeds failed, and forcing an unsupported speed can break connectivity.
* let `Parse_Interface_Config` return with error code directly, if the interface could not be found in the config, rendering `(( $PARSE_FOUND ))` check in caller functions redundant
* remove redundant CLI commands, which  /boot/dietpi/func/dietpi-set_hardware can/should be used directly
* show Exit or Back on whiptail menu cancel button, depending on whether the menu is the entry menu or not
* dietpi-set_hardware: eth-forcespeed: do not show a failure when disabling forced link speeds while /etc/systemd/system/ethtool_force_speed.service.d does not exist, as the script does now take the function's return code as exit code
* Do not assume that interfaces are enabled if they are not defined in any config. This was likely intended as default when applying settings, but it causes confusing status texts and can cause false positives in conflicting network checks. Show interfaces correctly as disabled, when they are. Instead, when applying settings, enable interfaces, unless they were explicitly disabled in their dedicated drop-in config, or requested as disabled via CLI option. That way, the status is shown correctly everywhere, and can be used as condition, while new interfaces are applied as enabled, unless explicitly requested otherwise.
* fix CURRENT_IFACE_DNS_STATIC condition, being no integer
* restart "auto" mode interfaces correctly via manual `ifdown`/`ifup`, since `ifup@.service` affects hotplug interfaces only.
* show boot mode in main menu only if interface is enabled
* show Disable/Remove options in interface menus only if the interface is actually defined in a config file already, and enabled respecively
* add Enable option to interface menu if interface is disabled
* pre-select current Ethernet link speed in respective menu
* skip `dietpi-set_hardware eth-forcespeed` as intended when the selection menu with missing supported speed detection warning is cancelled
* preserve last selected menu item in WiFi interface menu as well
* address shellcheck annotation about quotation in shell conditionals' right-handed value
* add proper input validation for gateway
* align "auto" link speed label so that it is shown as recommended from menu already
* fix syntax for CURRENT_IFACE_ENABLED check, which is a 0|1 integer
* clarify text on enable/disable options, that is is about whether the interface is automatically brought up at boot or not
*
@MichaIng
MichaIng force-pushed the copilot/move-menu-networkadapters-functionality branch from 40ad818 to 60f1c90 Compare August 23, 2026 01:49
* Assure Apply_Current_Interface returns with a positive return code, else the CLI apply call exits with error
* Skip the redundant Load_Interface_State call in Restart_Interface: It is called from Apply_Current_Interface only, which is called from CLI apply and the interface submenu. The prior exits afterwards, hence does not make any use of the updated info. The interface menu does its own Load_Interface_State call. When disabling an interface, the script returns to the main menu. The main menu however calls its own Load_Interface_State function with unconditional Get_Interface_Stored_Settings for all interfaces, to show the correct states.
* Use the new systemctl -v flag from Forky on, to show journalctl output during ifup@.service restarts, replacing the manual journalctl -f background job
Also relax the comment in the main config file. Many sort of manual configuration in /etc/network/interfaces does not cause issues like before. dietpi-network detects settings there, and migrates them automatically to drop-ins, when applying changes for a particular interface.

@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.

Okay, first boot setup works great as well. Merging this now, and starting an early beta to give more time for testing this tool.

@MichaIng
MichaIng merged commit aff4c99 into dev Aug 23, 2026
4 checks passed
@MichaIng
MichaIng deleted the copilot/move-menu-networkadapters-functionality branch August 23, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants