linux下如何修改网卡mac地址和随机产生mac地址

http://blog.chinaunix.net/uid-20564848-id-74257.html


luther@gliethttp:~$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:15:58:c2:85:c7 
          inet addr:172.16.32.115  Bcast:172.16.35.255 Mask:255.255.252.0
          inet6 addr: fe80::215:58ff:fec2:85c8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:440329 errors:1088 dropped:0 overruns:0 frame:0
          TX packets:426575 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:557743309 (557.7 MB)  TX bytes:32820176 (32.8 MB)
          Interrupt:23 Base address:0xd000
先看看当前mac地址为00:15:58:c2:85:c7
luther@gliethttp:~$ sudo ifconfig eth0 down
luther@gliethttp:~$ sudo ifconfig eth0 hw ether 00:15:58:c2:85:c8
luther@gliethttp:~$ sudo ifconfig eth0 up
luther@gliethttp:~$ sudo dhclient &

如何随机产生mac地址
luther@gliethttp:~$ echo $RANDOM | md5sum | sed 's/\(..\)/&:/g' | cut -c1-17
让开机自动修改mac信息和dhcp
luther@gliethttp:~$ sudo vim /etc/rc.local
# 追加如下内容
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:15:58:c2:85:c8
sudo ifconfig eth0 up
sudo dhclient &
如果需要,可以写一个脚本,当系统运行的时候被封mac之后,直接执行如下脚本
luther@gliethttp:~$ vim mac.sh
mac="00:"`echo $RANDOM | md5sum | sed 's/\(..\)/&:/g' | cut -c1-14`
echo $mac
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether $mac
sudo ifconfig eth0 up
sudo dhclient

08: 00: 20: 0A: 8C: 6D
一共6个字节48bits位,其中0-23位叫做组织唯一标志符 (organizationally unique ,是识别LAN(局域网)节点的标识.24-47位是由厂家自己分配。
其中第47位是组播地址标志位,47位为0为普通mac地址,为1表示广播或组播mac地址.
其中前3个字节由IEEE统一分配给网卡制造商,后3个字节由网卡制造商为自己生产的网卡对应一个唯一3字节数值,这样6个字节就构成了我们网卡的mac地址,每块网卡的mac地址唯一,不会重复 [luther.gliethttp]


猜你喜欢

转载自blog.csdn.net/sunjing_/article/details/80349922