@@ -1,72 +1,77 | |||
|
1 | 1 | # |
|
2 | 2 | # Setup Networking |
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | # Load utility functions |
|
6 | 6 | . ./functions.sh |
|
7 | 7 | |
|
8 | 8 | # Install and setup hostname |
|
9 | 9 | install_readonly files/network/hostname "${ETCDIR}/hostname" |
|
10 | 10 | sed -i "s/^rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hostname" |
|
11 | 11 | |
|
12 | 12 | # Install and setup hosts |
|
13 | 13 | install_readonly files/network/hosts "${ETCDIR}/hosts" |
|
14 | 14 | sed -i "s/rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hosts" |
|
15 | 15 | |
|
16 | 16 | # Setup hostname entry with static IP |
|
17 | 17 | if [ "$NET_ADDRESS" != "" ] ; then |
|
18 | 18 | NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/') |
|
19 | 19 | sed -i "s/^127.0.1.1/${NET_IP}/" "${ETCDIR}/hosts" |
|
20 | 20 | fi |
|
21 | 21 | |
|
22 | 22 | # Remove IPv6 hosts |
|
23 | 23 | if [ "$ENABLE_IPV6" = false ] ; then |
|
24 | 24 | sed -i -e "/::[1-9]/d" -e "/^$/d" "${ETCDIR}/hosts" |
|
25 | 25 | fi |
|
26 | 26 | |
|
27 | 27 | # Install hint about network configuration |
|
28 | 28 | install_readonly files/network/interfaces "${ETCDIR}/network/interfaces" |
|
29 | 29 | |
|
30 | 30 | # Install configuration for interface eth0 |
|
31 | 31 | install_readonly files/network/eth.network "${ETCDIR}/systemd/network/eth.network" |
|
32 | 32 | |
|
33 | 33 | if [ "$ENABLE_DHCP" = true ] ; then |
|
34 | 34 | # Enable DHCP configuration for interface eth0 |
|
35 | 35 | sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETCDIR}/systemd/network/eth.network" |
|
36 | 36 | |
|
37 | 37 | # Set DHCP configuration to IPv4 only |
|
38 | 38 | if [ "$ENABLE_IPV6" = false ] ; then |
|
39 | 39 | sed -i "s/DHCP=.*/DHCP=v4/" "${ETCDIR}/systemd/network/eth.network" |
|
40 | 40 | fi |
|
41 | 41 | |
|
42 | 42 | else # ENABLE_DHCP=false |
|
43 | 43 | # Set static network configuration for interface eth0 |
|
44 | 44 | sed -i\ |
|
45 | 45 | -e "s|DHCP=.*|DHCP=no|"\ |
|
46 | 46 | -e "s|Address=\$|Address=${NET_ADDRESS}|"\ |
|
47 | 47 | -e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\ |
|
48 | 48 | -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\ |
|
49 | 49 | -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\ |
|
50 | 50 | -e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\ |
|
51 | 51 | -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\ |
|
52 | 52 | -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\ |
|
53 | 53 | "${ETCDIR}/systemd/network/eth.network" |
|
54 | 54 | fi |
|
55 | 55 | |
|
56 | 56 | # Remove empty settings from network configuration |
|
57 | 57 | sed -i "/.*=\$/d" "${ETCDIR}/systemd/network/eth.network" |
|
58 | 58 | |
|
59 | 59 | # Enable systemd-networkd service |
|
60 | 60 | chroot_exec systemctl enable systemd-networkd |
|
61 | 61 | |
|
62 | 62 | # Install host.conf resolver configuration |
|
63 | 63 | install_readonly files/network/host.conf "${ETCDIR}/host.conf" |
|
64 | 64 | |
|
65 | 65 | # Enable network stack hardening |
|
66 | 66 | if [ "$ENABLE_HARDNET" = true ] ; then |
|
67 | 67 | # Install sysctl.d configuration files |
|
68 | 68 | install_readonly files/sysctl.d/82-rpi-net-hardening.conf "${ETCDIR}/sysctl.d/82-rpi-net-hardening.conf" |
|
69 | 69 | |
|
70 | 70 | # Setup resolver warnings about spoofed addresses |
|
71 | 71 | sed -i "s/^# spoof warn/spoof warn/" "${ETCDIR}/host.conf" |
|
72 | 72 | fi |
|
73 | ||
|
74 | # Enable time sync | |
|
75 | if [ "NET_NTP_1" != "" ] ; then | |
|
76 | chroot_exec systemctl enable systemd-timesyncd.service | |
|
77 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant