在Ubuntu 14.04中设置永久MAC地址

由于我的ISP建立Internet的方式不同,我需要手动设置MAC地址才能上线。 到目前为止我一直在使用:

sudo ifconfig eth0 down sudo ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx sudo ifconfig eth0 up 

但是,每次启动计算机时都必须输入此命令。 如何永久设置MAC地址?

您可以使用udev规则自动在网络接口上设置MAC地址

创建文件/etc/udev/rules.d/99-custom-mac.rules并粘贴到其中:

 ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="XX:XX:XX:XX:XX:XX", RUN+="/sbin/ip link set dev %k address YY:YY:YY:YY:YY:YY" 

其中XX:XX:XX:XX:XX:XX是你的界面的原始MAC地址(你可以在ip link的输出中得到它)和YY:YY:YY:YY:YY:YY是新的MAC地址你想强制执行。

要使更改生效,您可以运行

 sudo udevadm control --reload 

但我怀疑它是否有效,因此可能需要重新启动

您可以使用以下命令创建shell脚本:

 sudo ifconfig eth0 down sudo ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx sudo ifconfig eth0 up 

使用.sh扩展名保存文件并使其启动程序(“添加脚本”并选择您的脚本文件)

告诉我它是怎么回事?

对不起,我的英语不好。

复制终端中的所有内容


sudo ifconfig eth0 down && sudo ifconfig eth0 hw ether 00:4a:82:d5:e4:c6 && sudo ifconfig eth0 up