aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Wagner <mail@jwagner.eu>2016-03-05 08:31:17 +0100
committerJan Wagner <mail@jwagner.eu>2016-03-05 08:31:17 +0100
commit507dc9d2f06c3de8353b1e9cda8763f567472be9 (patch)
treef8edd3a76a850a018c2731b199ceee6cb99ba966
parent015289064dc3520582a24534ea810f1808ab4a1f (diff)
parentcb91ab1abbaeb94ddb69c9050640e48546e55068 (diff)
downloadrpi2-gen-image-507dc9d2f06c3de8353b1e9cda8763f567472be9.tar.gz
rpi2-gen-image-507dc9d2f06c3de8353b1e9cda8763f567472be9.tar.bz2
rpi2-gen-image-507dc9d2f06c3de8353b1e9cda8763f567472be9.zip
static ip patch by vknecht
-rw-r--r--README.md28
-rwxr-xr-xrpi2-gen-image.sh35
2 files changed, 61 insertions, 2 deletions
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 <<EOM >$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 <<EOM >$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 <<EOM >$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 <<EOM >$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