1、临时修改
sudo /sbin/ifconfig eth0 down#关闭网卡设备
sudo /sbin/ifconfig eth0 hw ether c8:27:ea:01:8b:31#修改 MAC 地址
sudo /sbin/ifconfig eth0 up#重新启用网卡
2. 永久修改(两种方法)
方法一
以上只是暂时修改mac地址,如果需要每次系统启动后,都自动修改好MAC地址的话,那么可以将以上命令写入启动脚本中。
pi@raspberrypi:~ $ sudo nano /etc/rc.local
GNU nano 2.2.6 File: /etc/rc.local
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
#sudo /sbin/ifconfig eth0 down
#sudo /sbin/ifconfig eth0 hw ether c8:27:ea:01:8b:31
#sudo /sbin/ifconfig eth0 up
exit 0
方法二
直接编辑 /etc/network/interfaces 文件,在 iface eth0 inet static 后面添加一行:
pre-up ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx(要改成的MAC)
编辑interfaces文件
pi@raspberrypi:~ $ sudo nano /etc/network/interfaces
GNU nano 2.2.6 File: /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd.
#or static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'.
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
#iface eth0 inet manual
iface eth0 inet static
pre-up ifconfig eth0 hw ether c8:27:ea:01:8b:31
address 192.168.1.50
netmask 255.255.255.0
gateway 192.168.1.1
以上可以解决路由器查封MAC地址,导致客户端无法ping通网关和不能上网,拼网关响应很慢且反回为:
pi@raspberrypi:~ $ ping www.baidu.com
ping: unknown host www.baidu.com
pi@raspberrypi:~ $ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
From 192.168.1.50 icmp_seq=9 Destination Host Unreachable
From 192.168.1.50 icmp_seq=10 Destination Host Unreachable
From 192.168.1.50 icmp_seq=11 Destination Host Unreachable
注意:本文归作者所有,未经作者允许,不得转载