4 # network configuration using ubuntu's netplan.io
7 echo "Generating netplan configuration for $IFNAME ($METHOD)" >&2
8 echo "# generated by FAI"
11 echo " renderer: $RENDERER"
21 echo " addresses: [$CIDR]"
22 echo " gateway4: $GATEWAYS_1"
24 echo " search: [$DOMAIN]"
25 echo " addresses: [${DNSSRVS// /, }]"
32 # classic network configuration using /etc/network/interfaces
35 echo "Generating interface configuration for $IFNAME ($METHOD)" >&2
36 echo "# generated by FAI"
38 echo "iface $IFNAME inet $METHOD"
42 echo " gateway $GATEWAYS"
49 # determine predictable network names only for stretch and above
52 [ $do_init_tasks -eq 0 ] && return
53 [ -z "$NIC1" ] && return
55 fields
="ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH"
56 for field
in $fields; do
57 name
=$
(udevadm info
/sys
/class
/net
/$NIC1 |
sed -rn "s/^E: $field=(.+)/\1/p")
64 # try to get altname net dev
65 name
=$
(ip link show
$NIC1 |
awk '/altname / { print $2 }')
70 echo "$0: error: could not find systemd predictable network name. Using $NIC1."
74 if [ -z "$NIC1" ]; then
75 echo "WARNING: \$NIC1 is not defined. Cannot add ethernet to /etc/network/interfaces."
77 CIDR
=$
(ip
--br ad sh
$NIC1|
awk '{print $3}')
82 ifclass DHCPC
&& METHOD
=dhcp || METHOD
=static
83 ifclass XORG
&& RENDERER
=NetworkManager || RENDERER
=networkd
85 if [ -d $target/etc
/netplan
]; then
86 # Ubuntu >= 17.10 with netplan.io
87 if [ -n "$NIC1" ]; then
88 netplan_yaml
$NIC1 $METHOD > $target/etc
/netplan
/01-${NIC1}.yaml
90 elif [ -d $target/etc
/network
/interfaces.d
]; then
91 # ifupdown >= 0.7.41 (Debian >= 8, Ubuntu >= 14.04)
92 iface_stanza lo loopback
> $target/etc
/network
/interfaces.d
/lo
94 if [ -n "$NIC1" -a ! -f $target/etc
/NetworkManager
/NetworkManager.conf
]; then
95 iface_stanza
$NIC1 $METHOD > $target/etc
/network
/interfaces.d
/$NIC1
99 iface_stanza lo loopback
100 iface_stanza
$NIC1 $METHOD
101 ) > $target/etc
/network
/interfaces
104 if ! ifclass DHCPC
; then
105 [ -n "$NETWORK" ] && echo "localnet $NETWORK" > $target/etc
/networks
106 if [ ! -L $target/etc
/resolv.conf
-a -e /etc
/resolv.conf
]; then
107 cp -p /etc
/resolv.conf
$target/etc
113 # here fcopy is mostly used, when installing a client for running in a
114 # different subnet than during the installation
115 fcopy
-iM /etc
/resolv.conf
116 fcopy
-iM /etc
/network
/interfaces
/etc
/networks