github.com/hashicorp/packer@v1.14.3/examples/hcl/linux/etc/scripts/030-networking.sh (about) 1 #!/bin/sh -eux 2 3 ubuntu_version="`lsb_release -r | awk '{print $2}'`"; 4 major_version="`echo $ubuntu_version | awk -F. '{print $1}'`"; 5 6 if [ "$major_version" -ge "18" ]; then 7 echo "Create netplan config for eth0" 8 cat <<EOF >/etc/netplan/01-netcfg.yaml; 9 network: 10 version: 2 11 ethernets: 12 eth0: 13 dhcp4: true 14 EOF 15 else 16 # Adding a 2 sec delay to the interface up, to make the dhclient happy 17 echo "pre-up sleep 2" >> /etc/network/interfaces; 18 fi 19 20 if [ "$major_version" -ge "16" ]; then 21 # Disable Predictable Network Interface names and use eth0 22 sed -i 's/en[[:alnum:]]*/eth0/g' /etc/network/interfaces; 23 sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 \1"/g' /etc/default/grub; 24 update-grub; 25 fi