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]


  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值