diff options
author | nachoparker <nacho@ownyourbits.com> | 2018-06-18 16:00:37 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2018-06-18 17:19:25 +0300 |
commit | 7b2737bf5fbb1c5fa597f60d4adbe80521e56717 (patch) | |
tree | 44e7fca6b885363f56dce201cc500a79499bcbf5 /etc | |
parent | 7ac184752e96d098bb87767c26f1313323fbe961 (diff) |
nc-static-IP: autodetect default interfacev0.57.2
Diffstat (limited to 'etc')
-rw-r--r-- | etc/ncp-config.d/nc-static-IP.sh | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/etc/ncp-config.d/nc-static-IP.sh b/etc/ncp-config.d/nc-static-IP.sh index 30f5e9bd..25e089d9 100644 --- a/etc/ncp-config.d/nc-static-IP.sh +++ b/etc/ncp-config.d/nc-static-IP.sh @@ -18,6 +18,8 @@ configure() local GW="$( ip r | grep "default via" | awk '{ print $3 }' )" local DNS="$( grep nameserver /etc/resolv.conf | head -1 | awk '{ print $2 }' )" [[ "$DNS" == "" ]] && DNS="$GW" + local IFACE="$( ip r | grep "default via" | awk '{ print $5 }' | head -1 )" + [[ "$IFACE" == "" ]] && { echo "Couldn't find default interface"; exit 1; } ## DHCPCD [[ -f /etc/dhcpcd.conf ]] && { @@ -34,7 +36,7 @@ configure() cat >> /etc/dhcpcd.conf <<EOF # NextCloudPi autogenerated # don't modify! better use ncp-config -interface eth0 +interface $IFACE static ip_address=$IP_/24 static routers=$GW static domain_name_servers=$DNS @@ -53,10 +55,10 @@ EOF [[ $ACTIVE_ != "yes" ]] && { cat > /etc/network/interfaces <<EOF # Wired adapter #1 -allow-hotplug eth0 -no-auto-down eth0 -auto eth0 -iface eth0 inet dhcp +allow-hotplug $IFACE +no-auto-down $IFACE +auto $IFACE +iface $IFACE inet dhcp # Local loopback auto lo @@ -75,10 +77,10 @@ source /etc/network/interfaces.d/* auto lo iface lo inet loopback -# Interface eth0 -auto eth0 -allow-hotplug eth0 -iface eth0 inet static +# Interface $IFACE +auto $IFACE +allow-hotplug $IFACE +iface $IFACE inet static address $IP_ netmask 255.255.255.0 gateway $GW |