脚本
需要安装ifconfig工具
#!/bin/bash
#ifconfig ens33
address=$1
netinterface=$3
sudo ifconfig netinterface down
sudo ifconfig netinterface $address netmask 255.255.255.0 hw ether 00:0c:29:b6:12:$2
sudo ifconfig netinterface up
#sleep 1s
echo $netinterface : $address
使用
第一个参数为设置本地的ip地址
第二个参数为本地的mac地址的最后一位
第三个参数为网口名称
sudo ./脚本.sh 10.0.2.101 11 ens33
效果
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.101 netmask 255.255.255.0 broadcast 10.0.2.255
ether 00:0c:29:b6:12:11 txqueuelen 1000 (以太网)
RX packets 169 bytes 84349 (84.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 118 bytes 14128 (14.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0