#!/bin/bash # # Copyright (c) Authors: https://www.armbian.com/authors # # This file is licensed under the terms of the GNU General Public # License version 2. This program is licensed "as is" without any # warranty of any kind, whether express or implied. # Functions: # # show_motd_warning # generate_random_mac # set_fixed_mac export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin my_name="${0##*/}" Log=/var/log/armbian-hardware-monitor.log show_motd_warning() { cat > /etc/update-motd.d/90-warning </dev/null; then return fi local netplan_config_file="/etc/netplan/20-eth-fixed-mac.yaml" # Initialize a new Netplan config file cat <<- EOF > "${netplan_config_file}" network: version: 2 ethernets: EOF # Iterate over each Ethernet interface for iface in $(ip link | awk -F: '$0 !~ "lo|vir|wl|^[^0-9]"{print $2;getline}' | sed 's/^[ \t]*//' | grep "^e\|^wan\|^lan") do generate_random_mac # Append the MAC address configuration for the interface to the Netplan configuration file cat <<- EOF >> "${netplan_config_file}" $iface: macaddress: $MACADDR EOF done # Change the file permissions according to https://netplan.readthedocs.io/en/stable/security/ chmod 600 "${netplan_config_file}" # Apply the Netplan configuration netplan apply }