#!/bin/bash # Enable static IP or DHCP for Raspbian # # Copyleft 2017 by Ignacio Nunez Hernanz # GPL licensed (see end of file) * Use at your own risk! # # More at: https://ownyourbits.com # ACTIVE_=no IP_=192.168.1.130 DESCRIPTION="Set up a static IP address (on), or DHCP (off)" 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 ]] && { # delete NCP config grep -q "^# NextCloudPi autogenerated" /etc/dhcpcd.conf && \ sed -i '/^# NextCloudPi autogenerated/,+6d' /etc/dhcpcd.conf [[ $ACTIVE_ != "yes" ]] && { systemctl restart dhcpcd echo "DHCP enabled" return } cat >> /etc/dhcpcd.conf < /etc/network/interfaces < /etc/network/interfaces <