Files
bee/iso/overlay/usr/local/bin/netconf
Michael Chus c9f5224c42 feat(console): add netconf command for quick network setup
Interactive script: lists interfaces, DHCP or static IP config.
Shown as hint in tty1 welcome message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-27 21:07:14 +03:00

51 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Quick network configurator for the local console.
set -e
# List interfaces (exclude lo)
IFACES=$(ip -o link show | awk -F': ' '$2 != "lo" {print $2}' | cut -d@ -f1)
echo "Interfaces:"
i=1
for iface in $IFACES; do
ip=$(ip -4 addr show "$iface" 2>/dev/null | awk '/inet /{print $2}' | head -1)
echo " $i) $iface ${ip:-no IP}"
i=$((i+1))
done
echo ""
printf "Interface name [or Enter to pick first]: "
read IFACE
if [ -z "$IFACE" ]; then
IFACE=$(echo "$IFACES" | head -1)
fi
echo "Selected: $IFACE"
echo ""
echo " 1) DHCP"
echo " 2) Static"
printf "Mode [1]: "
read MODE
MODE=${MODE:-1}
if [ "$MODE" = "1" ]; then
echo "Running DHCP on $IFACE..."
dhclient -v "$IFACE"
else
printf "IP address (e.g. 192.168.1.100/24): "
read ADDR
printf "Gateway (e.g. 192.168.1.1): "
read GW
printf "DNS [8.8.8.8]: "
read DNS
DNS=${DNS:-8.8.8.8}
ip addr flush dev "$IFACE"
ip addr add "$ADDR" dev "$IFACE"
ip link set "$IFACE" up
ip route add default via "$GW"
echo "nameserver $DNS" > /etc/resolv.conf
echo "Done."
fi
echo ""
ip -4 addr show "$IFACE"