diff --git a/README.md b/README.md index ef194c3..f1e9572 100644 --- a/README.md +++ b/README.md @@ -123,35 +123,74 @@ Set extra xkb configuration options. --- #### Networking settings (DHCP): -This parameter is used to set up networking auto-configuration in `/etc/systemd/network/eth.network`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.` +This parameter `ENABLE_ETH_DHCP` is used to set up networking auto-configuration in `/etc/systemd/network/eth0.network`. This parameter `ENABLE_WIFI_DHCP` is used to set up networking auto-configuration in `/etc/systemd/network/wlan0.network`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.` -##### `ENABLE_DHCP`=true +##### `ENABLE_ETH_DHCP`=true Set the system to use DHCP. This requires an DHCP server. +##### `ENABLE_WIFI_DHCP`=true +Set the system to use DHCP. This requires an DHCP server. + +--- + +#### Networking settings (ethernet static): +These parameters are used to set up a static networking configuration in `/etc/systemd/network/eth0.network`. The following static networking parameters are only supported if `ENABLE_ETH_DHCP` was set to `false`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`. + +##### `NET_ETH_ADDRESS`="" +Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24". + +##### `NET_ETH_GATEWAY`="" +Set the IP address for the default gateway. + +##### `NET_ETH_DNS_1`="" +Set the IP address for the first DNS server. + +##### `NET_ETH_DNS_2`="" +Set the IP address for the second DNS server. + +##### `NET_ETH_DNS_DOMAINS`="" +Set the default DNS search domains to use for non fully qualified hostnames. + +##### `NET_ETH_NTP_1`="" +Set the IP address for the first NTP server. + +##### `NET_ETH_NTP_2`="" +Set the IP address for the second NTP server. + +--- + +#### Networking settings (WIFI): + +##### `NET_WIFI_SSID`="" +Set to your WIFI SSID + +##### `NET_WIFI_WPAPSK`="" +Set your WPA/WPA2 PSK + --- -#### Networking settings (static): -These parameters are used to set up a static networking configuration in `/etc/systemd/network/eth.network`. The following static networking parameters are only supported if `ENABLE_DHCP` was set to `false`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`. +#### Networking settings (WIFI static): +These parameters are used to set up a static networking configuration in `/etc/systemd/network/wlan0.network`. The following static networking parameters are only supported if `ENABLE_WIFI_DHCP` was set to `false`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`. -##### `NET_ADDRESS`="" +##### `NET_WIFI_ADDRESS`="" Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24". -##### `NET_GATEWAY`="" +##### `NET_WIFI_GATEWAY`="" Set the IP address for the default gateway. -##### `NET_DNS_1`="" +##### `NET_WIFI_DNS_1`="" Set the IP address for the first DNS server. -##### `NET_DNS_2`="" +##### `NET_WIFI_DNS_2`="" Set the IP address for the second DNS server. -##### `NET_DNS_DOMAINS`="" +##### `NET_WIFI_DNS_DOMAINS`="" Set the default DNS search domains to use for non fully qualified hostnames. -##### `NET_NTP_1`="" +##### `NET_WIFI_NTP_1`="" Set the IP address for the first NTP server. -##### `NET_NTP_2`="" +##### `NET_WIFI_NTP_2`="" Set the IP address for the second NTP server. --- @@ -188,7 +227,7 @@ Install and enable OpenSSH service. The default configuration of the service doe Allow the installation of non-free Debian packages that do not comply with the DFSG. This is required to install closed-source firmware binary blobs. ##### `ENABLE_WIRELESS`=false -Download and install the [closed-source firmware binary blob](https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm) that is required to run the internal wireless interface of the Raspberry Pi model `3`. This parameter is ignored if the specified `RPI_MODEL` is not `3`. +Download and install the [closed-source firmware binary blob](https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm) that is required to run the internal wireless interface of the Raspberry Pi model `3`. This parameter is ignored if the specified `RPI_MODEL` is not `0`,`3`,`3P`,`4`. ##### `ENABLE_RSYSLOG`=true If set to false, disable and uninstall rsyslog (so logs will be available only in journal files) diff --git a/bootstrap.d/14-fstab.sh b/bootstrap.d/14-fstab.sh index 88f18f5..761ebaf 100644 --- a/bootstrap.d/14-fstab.sh +++ b/bootstrap.d/14-fstab.sh @@ -39,16 +39,16 @@ if [ "$ENABLE_INITRAMFS" = true ] ; then fi if [ "$CRYPTFS_DROPBEAR" = true ] ; then - if [ "$ENABLE_DHCP" = false ] ; then + if [ "$ENABLE_ETH_DHCP" = false ] ; then # Get cdir from NET_ADDRESS e.g. 24 - cdir=$(printf "%s" "${NET_ADDRESS}" | cut -d '/' -f2) + cdir=$(printf "%s" "${NET_ETH_ADDRESS}" | cut -d '/' -f2) # Convert cdir ro netmask e.g. 24 to 255.255.255.0 NET_MASK=$(cdr2mask "$cdir") # Write static ip settings to "${ETC_DIR}"/initramfs-tools/initramfs.conf # ip=:::::: - sed -i "\$a\nIP=${NET_ADDRESS}::${NET_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf + sed -i "\$a\nIP=${NET_ETH_ADDRESS}::${NET_ETH_GATEWAY}:${NET_MASK}:${HOSTNAME}:" "${ETC_DIR}"/initramfs-tools/initramfs.conf else sed -i "\$a\nIP=::::${HOSTNAME}::dhcp" "${ETC_DIR}"/initramfs-tools/initramfs.conf fi diff --git a/bootstrap.d/20-networking.sh b/bootstrap.d/20-networking.sh index a1213db..a9bbfd2 100644 --- a/bootstrap.d/20-networking.sh +++ b/bootstrap.d/20-networking.sh @@ -14,8 +14,8 @@ install_readonly files/network/hosts "${ETC_DIR}/hosts" sed -i "s/RaspberryPI/${HOSTNAME}/" "${ETC_DIR}/hosts" # Setup hostname entry with static IP -if [ "$NET_ADDRESS" != "" ] ; then - NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/') +if [ "$NET_ETH_ADDRESS" != "" ] ; then + NET_IP=$(echo "${NET_ETH_ADDRESS}" | cut -f 1 -d'/') sed -i "s/^127.0.1.1/${NET_IP}/" "${ETC_DIR}/hosts" fi @@ -28,51 +28,92 @@ fi install_readonly files/network/interfaces "${ETC_DIR}/network/interfaces" # Install configuration for interface eth0 -install_readonly files/network/eth.network "${ETC_DIR}/systemd/network/eth.network" +install_readonly files/network/eth0.network "${ETC_DIR}/systemd/network/eth0.network" if [ "$RPI_MODEL" = 3P ] ; then -printf "\n[Link]\nGenericReceiveOffload=off\nTCPSegmentationOffload=off\nGenericSegmentationOffload=off" >> "${ETC_DIR}/systemd/network/eth.network" +printf "\n[Link]\nGenericReceiveOffload=off\nTCPSegmentationOffload=off\nGenericSegmentationOffload=off" >> "${ETC_DIR}/systemd/network/eth0.network" fi # Install configuration for interface wl* -install_readonly files/network/wlan.network "${ETC_DIR}/systemd/network/wlan.network" +install_readonly files/network/wlan0.network "${ETC_DIR}/systemd/network/wlan0.network" #always with dhcp since wpa_supplicant integration is missing -sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/wlan.network" +sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/wlan0.network" -if [ "$ENABLE_DHCP" = true ] ; then +if [ "$ENABLE_ETH_DHCP" = true ] ; then # Enable DHCP configuration for interface eth0 - sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/eth.network" + sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/eth0.network" # Set DHCP configuration to IPv4 only if [ "$ENABLE_IPV6" = false ] ; then - sed -i "s/DHCP=.*/DHCP=v4/" "${ETC_DIR}/systemd/network/eth.network" + sed -i "s/DHCP=.*/DHCP=v4/" "${ETC_DIR}/systemd/network/eth0.network" + sed '/IPv6PrivacyExtensions=true/d' "${ETC_DIR}/systemd/network/eth0.network" fi -else # ENABLE_DHCP=false +else # ENABLE_ETH_DHCP=false # Set static network configuration for interface eth0 sed -i\ -e "s|DHCP=.*|DHCP=no|"\ - -e "s|Address=\$|Address=${NET_ADDRESS}|"\ - -e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\ - -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\ - -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\ - -e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\ - -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\ - -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\ - "${ETC_DIR}/systemd/network/eth.network" + -e "s|Address=\$|Address=${NET_ETH_ADDRESS}|"\ + -e "s|Gateway=\$|Gateway=${NET_ETH_GATEWAY}|"\ + -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_ETH_DNS_1}|"\ + -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_ETH_DNS_2}|"\ + -e "s|Domains=\$|Domains=${NET_ETH_DNS_DOMAINS}|"\ + -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_ETH_NTP_1}|"\ + -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_ETH_NTP_2}|"\ + "${ETC_DIR}/systemd/network/eth0.network" fi +if [ "$ENABLE_WIFI_DHCP" = true ] ; then + # Enable DHCP configuration for interface eth0 + sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETC_DIR}/systemd/network/wlan0.network" + + # Set DHCP configuration to IPv4 only + if [ "$ENABLE_IPV6" = false ] ; then + sed -i "s/DHCP=.*/DHCP=v4/" "${ETC_DIR}/systemd/network/wlan0.network" + sed '/IPv6PrivacyExtensions=true/d' "${ETC_DIR}/systemd/network/wlan0.network" + fi + +else # ENABLE_ETH_DHCP=false + # Set static network configuration for interface eth0 + sed -i\ + -e "s|DHCP=.*|DHCP=no|"\ + -e "s|Address=\$|Address=${NET_WIFI_ADDRESS}|"\ + -e "s|Gateway=\$|Gateway=${NET_WIFI_GATEWAY}|"\ + -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_WIFI_DNS_1}|"\ + -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_WIFI_DNS_2}|"\ + -e "s|Domains=\$|Domains=${NET_WIFI_DNS_DOMAINS}|"\ + -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_WIFI_NTP_1}|"\ + -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_WIFI_NTP_2}|"\ + "${ETC_DIR}/systemd/network/wlan0.network" +fi + +printf " +ctrl_interface=/run/wpa_supplicant +ctrl_interface_group=wheel +update_config=1 +eapol_version=1 +ap_scan=1 +fast_reauth=1 + +" > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf + +#Configure WPA_supplicant +chroot_exec wpa_passphrase "$NET_SSID" "$NET_WPAPSK" >> /etc/wpa_supplicant/wpa_supplicant-wlan0.conf + +chroot_exec systemctl enable wpa_supplicant.service +chroot_exec systemctl enable wpa_supplicant@wlan0.service + # Remove empty settings from network configuration -sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/eth.network" +sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/eth0.network" # Remove empty settings from wlan configuration -sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/wlan.network" +sed -i "/.*=\$/d" "${ETC_DIR}/systemd/network/wlan0.network" # Move systemd network configuration if required by Debian release -mv -v "${ETC_DIR}/systemd/network/eth.network" "${LIB_DIR}/systemd/network/10-eth.network" +mv -v "${ETC_DIR}/systemd/network/eth0.network" "${LIB_DIR}/systemd/network/10-eth0.network" # If WLAN is enabled copy wlan configuration too if [ "$ENABLE_WIRELESS" = true ] ; then - mv -v "${ETC_DIR}/systemd/network/wlan.network" "${LIB_DIR}/systemd/network/11-wlan.network" + mv -v "${ETC_DIR}/systemd/network/wlan0.network" "${LIB_DIR}/systemd/network/11-wlan0.network" fi rm -fr "${ETC_DIR}/systemd/network" diff --git a/files/firstboot/42-config-ifnames.sh b/files/firstboot/42-config-ifnames.sh index 9724155..9bb9bfe 100644 --- a/files/firstboot/42-config-ifnames.sh +++ b/files/firstboot/42-config-ifnames.sh @@ -1,13 +1,28 @@ logger -t "rc.firstboot" "Configuring network interface name" -INTERFACE_NAME=$(dmesg | grep "renamed from eth0" | awk -F ":| " '{ print $9 }') +INTERFACE_NAME_ETH=$(dmesg | grep "renamed from eth0" | awk -F ":| " '{ print $9 }') +INTERFACE_NAME_WIFI=$(dmesg | grep "renamed from wlan0" | awk -F ":| " '{ print $9 }') -if [ ! -z INTERFACE_NAME ] ; then - if [ -r "/etc/systemd/network/eth.network" ] ; then - sed -i "s/eth0/${INTERFACE_NAME}/" /etc/systemd/network/eth.network +if [ ! -z INTERFACE_NAME_ETH ] ; then + if [ -r "/etc/systemd/network/eth0.network" ] ; then + sed -i "s/eth0/${INTERFACE_NAME_ETH}/" /etc/systemd/network/eth0.network fi - if [ -r "/lib/systemd/network/10-eth.network" ] ; then - sed -i "s/eth0/${INTERFACE_NAME}/" /lib/systemd/network/10-eth.network + if [ -r "/lib/systemd/network/10-eth0.network" ] ; then + sed -i "s/eth0/${INTERFACE_NAME_ETH}/" /lib/systemd/network/10-eth0.network fi + # Move config to new interface name + mv /etc/systemd/network/eth0.network /etc/systemd/network/"${INTERFACE_NAME_ETH}".network +fi + +if [ ! -z INTERFACE_NAME_WIFI ] ; then + if [ -r "/etc/systemd/network/wlan0.network" ] ; then + sed -i "s/wlan0/${INTERFACE_NAME_WIFI}/" /etc/systemd/network/wlan0.network + fi + + if [ -r "/lib/systemd/network/11-wlan0.network" ] ; then + sed -i "s/wlan0/${INTERFACE_NAME_WIFI}/" /lib/systemd/network/11-wlan0.network + fi + # Move config to new interface name + mv /etc/systemd/network/wlan0.network /etc/systemd/network/"${INTERFACE_NAME_WIFI}".network fi diff --git a/files/network/eth.network b/files/network/eth0.network similarity index 91% rename from files/network/eth.network rename to files/network/eth0.network index db519c9..143ca4b 100644 --- a/files/network/eth.network +++ b/files/network/eth0.network @@ -2,6 +2,8 @@ Name=eth0 [Network] +RouteMetric=10 +IPv6PrivacyExtensions=true DHCP=no Address= Gateway= diff --git a/files/network/wlan.network b/files/network/wlan0.network similarity index 91% rename from files/network/wlan.network rename to files/network/wlan0.network index 5f252c3..cfc90ca 100644 --- a/files/network/wlan.network +++ b/files/network/wlan0.network @@ -2,6 +2,8 @@ Name=wlan0 [Network] +RouteMetric=20 +IPv6PrivacyExtensions=true DHCP=no Address= Gateway= diff --git a/rpi23-gen-image.sh b/rpi23-gen-image.sh index a67ad40..74c4782 100755 --- a/rpi23-gen-image.sh +++ b/rpi23-gen-image.sh @@ -113,16 +113,29 @@ XKB_VARIANT=${XKB_VARIANT:=""} XKB_OPTIONS=${XKB_OPTIONS:=""} # Network settings (DHCP) -ENABLE_DHCP=${ENABLE_DHCP:=true} +ENABLE_ETH_DHCP=${ENABLE_ETH_DHCP:=true} +ENABLE_WIFI_DHCP=${ENABLE_ETH_DHCP:=true} # Network settings (static) -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:=""} +NET_ETH_ADDRESS=${NET_ETH_ADDRESS:=""} +NET_ETH_GATEWAY=${NET_ETH_GATEWAY:=""} +NET_ETH_DNS_1=${NET_ETH_DNS_1:=""} +NET_ETH_DNS_2=${NET_ETH_DNS_2:=""} +NET_ETH_DNS_DOMAINS=${NET_ETH_DNS_DOMAINS:=""} +NET_ETH_NTP_1=${NET_ETH_NTP_1:=""} +NET_ETH_NTP_2=${NET_ETH_NTP_2:=""} + +NET_WIFI_SSID=${NET_SSID:=""} +NET_WIFI_WPAPSK=${NET_WPAPSK:=""} + +# Network settings (static) +NET_WIFI_ADDRESS=${NET_WIFI_ADDRESS:=""} +NET_WIFI_GATEWAY=${NET_WIFI_GATEWAY:=""} +NET_WIFI_DNS_1=${NET_WIFI_DNS_1:=""} +NET_WIFI_DNS_2=${NET_WIFI_DNS_2:=""} +NET_WIFI_DNS_DOMAINS=${NET_WIFI_DNS_DOMAINS:=""} +NET_WIFI_NTP_1=${NET_WIFI_NTP_1:=""} +NET_WIFI_NTP_2=${NET_WIFI_NTP_2:=""} # APT settings APT_PROXY=${APT_PROXY:=""} @@ -361,7 +374,7 @@ if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] || [ "$ APT_INCLUDES="${APT_INCLUDES},bluetooth,bluez" fi if [ "$ENABLE_WIRELESS" = true ] ; then - APT_INCLUDES="${APT_INCLUDES},wireless-tools,crda,wireless-regdb" + APT_INCLUDES="${APT_INCLUDES},wireless-tools,crda,wireless-regdb,wpasupplicant" fi else # Raspberry PI 1,1P,2 without Wifi and bluetooth onboard # Check if the internal wireless interface is not supported by the RPi model