From 7ddaa7958999a0553c18600daabc9fd0d3376c6f Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Sat, 11 Jul 2026 12:42:42 +0200 Subject: [PATCH] fixed dns --- postinstall/init.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/postinstall/init.sh b/postinstall/init.sh index b7906c9..a375abb 100644 --- a/postinstall/init.sh +++ b/postinstall/init.sh @@ -3,12 +3,13 @@ # Sometimes the network is slow, wait a bit sleep 10 -# Get the current DHCP network address (and gateway) +# Get the current DHCP network address, gateway and DNS servers NIC=$(ip link | grep "^2:" | awk '{print $2}' | tr -d ":") IP_ADDRESS=$(ip address show ${NIC} | grep -E "inet " | awk '{print $2}') NETMASK=$(echo ${IP_ADDRESS} | sed 's/.*\///') IP_ADDRESS=$(echo ${IP_ADDRESS} | sed 's/\/.*//') GATEWAY=$(ip route | grep "default" | awk '{print $3}') +DNS_SERVERS=$(awk '/^nameserver/ {print $2}' /etc/resolv.conf) # Network interfaces (static address) cat << EOF > /etc/network/interfaces @@ -19,10 +20,16 @@ auto ${NIC} iface ${NIC} inet static address ${IP_ADDRESS}/${NETMASK} gateway ${GATEWAY} + dns-nameservers ${DNS_SERVERS} EOF # Tabs instead of spaces, neat the file sed -i 's/ /\t/gm' /etc/network/interfaces +# write a static resolv.conf +rm -f /etc/resolv.conf +for ns in ${DNS_SERVERS}; do + echo "nameserver ${ns}" >> /etc/resolv.conf +done # Hosts file cat << EOF > /etc/hosts