方法一、使用「ifconfig」命令
#!/bin/bash # 修改MAC地址 ifconfig eth0 hw ether 02:01:02:03:04:08 # 查看修改后的结果 ifconfig eth0
有关ifconfig命令,查看ifconfig(8)手册
方法二、使用「ip」命令
#!/bin/bash # 修改MAC地址 ip link set eth0 address 02:01:02:03:04:08 # 查看修改后的结果 ip link ls eth0 ip addr ls eth0
有关ip命令的使用方法,查看ip(8)手册。
方法三、使用「macchanger」命令
#!/bin/bash # 修改MAC地址 macchanger -m b2:aa:0e:56:ed:f7 eth0 # 查看修改结果,这里不再演示
有关macchanger命令的使用方法,查看macchanger(1)手册。
持久化保存新的MAC地址
在Debian/Ubuntu等类似的系统上,需要修改/etc/network/interfaces文件,在对应的iface部分中加入某些内容:
iface eth0 inet static address 172.16.4.1 netmask 255.255.255.0 **hwaddress ether 02:01:02:03:04:08**
上面的黑色加粗的字体是需要加入的内容。
参考文献
Change mac address with macchanger Linux command
Changing Your MAC Address/Linux