ConstStar
发布于 2024-11-29 / 19 阅读 / 0 评论 / 0 点赞

第一次开机随机mac地址

/etc/init.d/boot_init.sh

ifconfig eth0 down
ifconfig eth1 down

if [ ! -e "/boot/first/boot_mac_eth0" ] || [ ! -e "/boot/first/boot_mac_eth1" ] ;
then
   sudo macchanger -r eth0
   sudo macchanger -r eth1

   mac_address_eth0=$(ifconfig eth0 | grep ether | awk '{ print $2 }')
   mac_address_eth1=$(ifconfig eth1 | grep ether | awk '{ print $2 }')

   touch /boot/first/boot_mac_eth0
   touch /boot/first/boot_mac_eth1

   echo "$mac_address_eth0" > /boot/first/boot_mac_eth0
   echo "$mac_address_eth1" > /boot/first/boot_mac_eth1

   mac_address_eth0=$(cat /boot/first/boot_mac_eth0)
   mac_address_eth1=$(cat /boot/first/boot_mac_eth1)
   sudo ifconfig eth0 hw ether $mac_address_eth0
   sudo ifconfig eth1 hw ether $mac_address_eth1
fi

sudo ifconfig eth0 up
sudo ifconfig eth1 up

评论