openwrt手动修改mac

问题:多台openwrt设备在同一网络中使用产生MAC冲突

解决过程:

(红色的为新增加的部分)

1.修改 lan,wan mac地址

编辑 /etc/config/network
修改其中一段

config ‘interface’ ‘lan’
option ‘type’ ‘bridge’
option ‘ifname’ ‘eth0.0’
option ‘proto’ ‘static’
option ‘netmask’ ‘255.255.255.0’
option ‘ipaddr’ ‘192.168.200.1’
option ‘macaddr’ ‘d8:64:c7:5e:f1:c6’

config ‘interface’ ‘wan’
option ‘ifname’ ‘eth0.1’
option ‘proto’ ‘dhcp’
option ‘macaddr’ ‘d8:64:c7:5e:f1:c6’

2.修改 eth0 mac地址

编辑 /etc/rc.local
ifconfig eth0 down;ifconfig eth0 hw ether d8:64:c7:5e:f1:c6;ifconfig eth0 up

3.修改wireless mac地址

这就最纠结了直接修改 /etc/config/wireless中的mac是没用的,并且修改后无线网络会无法启动。
在研究了/sbin/wifi脚本后,只能通过迂回战术来进行解决。
编辑 /sbin/wifi
修改如下一段,增加内容
set_wifi_up() {                                   
       echo wifi_up;ls /tmp/runbssid=d8:64:c7:5f:f1:c6/ /var/run/hostapd-phy0.conf
       hostapd -P /var/run/wifi-phy0.pid -B /var/run/hostapd-phy0.conf

       local cfg=”$1″                  
       echo wifi_up 2;ls /tmp/run/*.conf
       local ifname=”$2″               
       echo wifi_up 3;ls /tmp/run/*.conf
       uci_set_state wireless “$cfg” up 1
       uci_set_state wireless “$cfg” ifname “$ifname”

}       

4.修改完成 

sync;reboot 重启,就能看到所有修改都生效了。