From 8c841853ea81ef1b9b25b16632f7bd1a03520405 2016-03-05 07:31:41 From: Jan Wagner Date: 2016-03-05 07:31:41 Subject: [PATCH] Merge branch 'vknecht-net-static' --- diff --git a/README.md b/README.md index 987ce62..f0ece3c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,6 @@ Set system `root` password. The same password is used for the created user `pi`. ##### `DEFLOCAL`="en_US.UTF-8" Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. The script variant `minbase` (ENABLE_MINBASE=true) doesn't install `locales`. - ##### `TIMEZONE`="Europe/Berlin" Set default system timezone. All available timezones can be found in the `/usr/share/zoneinfo/` directory. This setting can also be changed inside the running OS using the `dpkg-reconfigure tzdata` command. @@ -48,6 +47,33 @@ These options are used to configure keyboard layout in `/etc/default/keyboard` f ##### `XKBVARIANT`="" ##### `XKBOPTIONS`="" +#### Networking settings +These settings are used to set up networking configuration in `/etc/systemd/network/eth.network`. + +#####`ENABLE_DHCP`=true +Set the system to use DHCP. When set to "true", the following `NET_*` settings (used for static configuration) are ignored. + +#####`NET_ADDRESS`="" +Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24". + +#####`NET_GATEWAY`="" +Set the IP address for the default gateway. + +#####`NET_DNS_1`="" +Set the IP address for the first DNS server. + +#####`NET_DNS_2`="" +Set the IP address for the second DNS server. + +#####`NET_DNS_DOMAINS`="" +Set the default DNS search domains to use for non fully qualified host names. + +#####`NET_NTP_1`="" +Set the IP address for the first NTP server. + +#####`NET_NTP_2`="" +Set the IP address for the second NTP server. + #### Basic system features: ##### `ENABLE_CONSOLE`=true Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system. diff --git a/rpi2-gen-image.sh b/rpi2-gen-image.sh index b5170d5..2c88f3a 100755 --- a/rpi2-gen-image.sh +++ b/rpi2-gen-image.sh @@ -50,6 +50,18 @@ XKBLAYOUT=${XKBLAYOUT:=""} XKBVARIANT=${XKBVARIANT:=""} XKBOPTIONS=${XKBOPTIONS:=""} +# Network settings +ENABLE_DHCP=${ENABLE_DHCP:=true} +# NET_* settings are ignored when ENABLE_DHCP=true +# NET_ADDRESS is an IPv4 or IPv6 address and its prefix, separated by "/" +NET_ADDRESS=${NET_ADDRESS:=""} +NET_GATEWAY=${NET_GATEWAY:=""} +NET_DNS_1=${NET_DNS_1:=""} +NET_DNS_2=${NET_DNS_2:=""} +NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} +NET_NTP_1=${NET_NTP_1:=""} +NET_NTP_2=${NET_NTP_2:=""} + # APT settings APT_PROXY=${APT_PROXY:=""} APT_SERVER=${APT_SERVER:="ftp.debian.org"} @@ -308,6 +320,10 @@ cat <$R/etc/hosts 127.0.0.1 localhost 127.0.1.1 ${HOSTNAME} EOM +if [ "$NET_ADDRESS" != "" ] ; then +NET_IP=$(echo ${NET_ADDRESS} | cut -f 1 -d'/') +sed -i "s/^127.0.1.1/${NET_IP}/" $R/etc/hosts +fi # Set up IPv6 hosts if [ "$ENABLE_IPV6" = true ] ; then @@ -325,6 +341,7 @@ cat <$R/etc/network/interfaces # please configure your networks in '/etc/systemd/network/' EOM +if [ "$ENABLE_DHCP" = true ] ; then # Enable systemd-networkd DHCP configuration for interface eth0 cat <$R/etc/systemd/network/eth.network [Match] @@ -336,7 +353,23 @@ EOM # Set DHCP configuration to IPv4 only if [ "$ENABLE_IPV6" = false ] ; then - sed -i "s/=yes/=v4/" $R/etc/systemd/network/eth.network + sed -i "s/^DHCP=yes/DHCP=v4/" $R/etc/systemd/network/eth.network +fi +else # ENABLE_DHCP=false +cat <$R/etc/systemd/network/eth.network +[Match] +Name=eth0 + +[Network] +DHCP=no +Address=${NET_ADDRESS} +Gateway=${NET_GATEWAY} +DNS=${NET_DNS_1} +DNS=${NET_DNS_2} +Domains=${NET_DNS_DOMAINS} +NTP=${NET_NTP_1} +NTP=${NET_NTP_2} +EOM fi # Enable systemd-networkd service