20-networking.sh
77 lines
| 2.4 KiB
| application/x-sh
|
BashLexer
/ bootstrap.d / 20-networking.sh
Filip Pytloun
|
r56 | # | ||
Jan Wagner
|
r67 | # Setup Networking | ||
Filip Pytloun
|
r56 | # | ||
Jan Wagner
|
r67 | # Load utility functions | ||
Filip Pytloun
|
r56 | . ./functions.sh | ||
Jan Wagner
|
r71 | # Install and setup hostname | ||
Jan Wagner
|
r82 | install_readonly files/network/hostname "${ETCDIR}/hostname" | ||
sed -i "s/^rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hostname" | ||||
Jan Wagner
|
r67 | |||
Jan Wagner
|
r71 | # Install and setup hosts | ||
Jan Wagner
|
r82 | install_readonly files/network/hosts "${ETCDIR}/hosts" | ||
sed -i "s/rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hosts" | ||||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Setup hostname entry with static IP | ||
Filip Pytloun
|
r56 | if [ "$NET_ADDRESS" != "" ] ; then | ||
Jan Wagner
|
r75 | NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/') | ||
Jan Wagner
|
r82 | sed -i "s/^127.0.1.1/${NET_IP}/" "${ETCDIR}/hosts" | ||
Filip Pytloun
|
r56 | fi | ||
Jan Wagner
|
r71 | # Remove IPv6 hosts | ||
if [ "$ENABLE_IPV6" = false ] ; then | ||||
Jan Wagner
|
r82 | sed -i -e "/::[1-9]/d" -e "/^$/d" "${ETCDIR}/hosts" | ||
Filip Pytloun
|
r56 | fi | ||
Jan Wagner
|
r71 | # Install hint about network configuration | ||
Jan Wagner
|
r82 | install_readonly files/network/interfaces "${ETCDIR}/network/interfaces" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Install configuration for interface eth0 | ||
Jan Wagner
|
r82 | install_readonly files/network/eth.network "${ETCDIR}/systemd/network/eth.network" | ||
Jan Wagner
|
r71 | |||
Filip Pytloun
|
r56 | if [ "$ENABLE_DHCP" = true ] ; then | ||
Jan Wagner
|
r71 | # Enable DHCP configuration for interface eth0 | ||
Jan Wagner
|
r82 | sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETCDIR}/systemd/network/eth.network" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r70 | # Set DHCP configuration to IPv4 only | ||
Jan Wagner
|
r67 | if [ "$ENABLE_IPV6" = false ] ; then | ||
Jan Wagner
|
r82 | sed -i "s/DHCP=.*/DHCP=v4/" "${ETCDIR}/systemd/network/eth.network" | ||
Jan Wagner
|
r67 | fi | ||
Jan Wagner
|
r70 | |||
Filip Pytloun
|
r56 | else # ENABLE_DHCP=false | ||
Jan Wagner
|
r71 | # 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}|"\ | ||||
Jan Wagner
|
r82 | "${ETCDIR}/systemd/network/eth.network" | ||
Filip Pytloun
|
r56 | fi | ||
Jan Wagner
|
r71 | # Remove empty settings from network configuration | ||
Jan Wagner
|
r82 | sed -i "/.*=\$/d" "${ETCDIR}/systemd/network/eth.network" | ||
Jan Wagner
|
r71 | |||
Filip Pytloun
|
r56 | # Enable systemd-networkd service | ||
chroot_exec systemctl enable systemd-networkd | ||||
Jan Wagner
|
r71 | # Install host.conf resolver configuration | ||
Jan Wagner
|
r82 | install_readonly files/network/host.conf "${ETCDIR}/host.conf" | ||
Jan Wagner
|
r71 | |||
Filip Pytloun
|
r56 | # Enable network stack hardening | ||
if [ "$ENABLE_HARDNET" = true ] ; then | ||||
Jan Wagner
|
r71 | # Install sysctl.d configuration files | ||
Jan Wagner
|
r82 | install_readonly files/sysctl.d/82-rpi-net-hardening.conf "${ETCDIR}/sysctl.d/82-rpi-net-hardening.conf" | ||
Filip Pytloun
|
r56 | |||
Jan Wagner
|
r71 | # Setup resolver warnings about spoofed addresses | ||
Jan Wagner
|
r82 | sed -i "s/^# spoof warn/spoof warn/" "${ETCDIR}/host.conf" | ||
Filip Pytloun
|
r56 | fi | ||
Stephen A. Brandli
|
r85 | |||
# Enable time sync | ||||
if [ "NET_NTP_1" != "" ] ; then | ||||
chroot_exec systemctl enable systemd-timesyncd.service | ||||
fi | ||||