Skip to content

Commit c661625

Browse files
committed
feat: send hostname in DHCP requests
Read /etc/hostname and pass it to udhcpc via -x hostname option in both ethernet and wifi init scripts. This allows DHCP servers to register the device hostname, making it easier to identify NanoKVM devices on the network. Uses -x hostname: instead of -F for better compatibility with various DHCP server implementations (e.g. Mikrotik).
1 parent 4af32fc commit c661625

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

kvmapp/system/init.d/S30eth

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ EOF
1919
}
2020

2121
start() {
22+
HOSTNAME=$(cat /etc/hostname 2>/dev/null | head -1)
23+
HOSTNAME_OPT=""
24+
[ -n "$HOSTNAME" ] && HOSTNAME_OPT="-x hostname:$HOSTNAME"
25+
2226
ip addr flush dev eth0
2327
if [ -e /boot/eth.nodhcp ]; then
2428
while IFS= read -r line || [ -n "$line" ]; do
@@ -39,15 +43,15 @@ start() {
3943
done < /boot/eth.nodhcp
4044

4145
ip a show dev eth0 | grep inet > /dev/null || {
42-
udhcpc -i eth0 -t 3 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid &>/dev/null
46+
udhcpc -i eth0 -t 3 -T 1 -A 5 -b $HOSTNAME_OPT -p /run/udhcpc.eth0.pid &>/dev/null
4347
ip a show dev eth0 | grep inet > /dev/null
4448
} || {
4549
inet=$RESERVE_INET
4650
addr=${inet%/*}
4751
ip a add "$inet" brd + dev eth0
4852
} || exit 1
4953
else
50-
udhcpc -i eth0 -t 10 -T 1 -A 5 -b -p /run/udhcpc.eth0.pid &
54+
udhcpc -i eth0 -t 10 -T 1 -A 5 -b $HOSTNAME_OPT -p /run/udhcpc.eth0.pid &
5155
fi
5256
}
5357

kvmapp/system/init.d/S30wifi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ gen_dnsmasq_conf() {
4949
}
5050

5151
start() {
52+
HOSTNAME=$(cat /etc/hostname 2>/dev/null | head -1)
53+
HOSTNAME_OPT=""
54+
[ -n "$HOSTNAME" ] && HOSTNAME_OPT="-x hostname:$HOSTNAME"
55+
5256
echo "wifi mode: sta"
5357
ssid=""
5458
pass=""
@@ -73,7 +77,7 @@ start() {
7377
wpa_passphrase "$ssid" "$pass" >>/etc/wpa_supplicant.conf
7478
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
7579
if [ ! -e /boot/wifi.nodhcp ]; then
76-
(udhcpc -i wlan0 -t 10 -T 1 -A 5 -b -p /run/udhcpc.wlan0.pid) &
80+
(udhcpc -i wlan0 -t 10 -T 1 -A 5 -b $HOSTNAME_OPT -p /run/udhcpc.wlan0.pid) &
7781
fi
7882
}
7983

0 commit comments

Comments
 (0)