环境
Centos 7.7 Minimal
GNU MAC changer 1.7.0
查询网卡和MAC地址
[root@localhost ~]# ip link show1: lo:mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:002: ens33: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:48:4c:9a brd ff:ff:ff:ff:ff:ff
网卡名称是ens33,MAC地址是00:0c:29:48:4c:9a。请记下自己的MAC地址,稍后做完实验恢复到原来的MAC地址。
使用macchanger工具更改MAC地址
Macchanger可以查看、修改MAC地址。
安装macchanger
[root@localhost ~]# git clone https://github.com/alobbs/macchanger
[root@localhost ~]# yum -y install autoconf automake gcc gcc-c++ texinfo
如何使用macchanger
使用下面的 命令 生成一个随机的mac地址为ens33网卡:
[root@localhost ~]# macchanger -r ens33
Current MAC: 00:0c:29:48:4c:9a (VMware, Inc.)
Permanent MAC: 00:0c:29:48:4c:9a (VMware, Inc.)
New MAC: a2:97:a2:55:53:be (unknown)
查看一下ens33的MAC地址是否改变了
[root@localhost ~]# ip link show ens332: ens33: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether a2:97:a2:55:53:be brd ff:ff:ff:ff:ff:ff
可以更改成一个自己指定的mac地址,使用下面的 命令 更改:
[root@localhost ~]# macchanger --mac=XX:XX:XX:XX:XX:XX
如果想要恢复到真实的MAC地址,请使用下面的命令:
[root@localhost ~]# macchanger -p ens33
Current MAC: a2:97:a2:55:53:be (unknown)
Permanent MAC: 00:0c:29:48:4c:9a (VMware, Inc.)
New MAC: 00:0c:29:48:4c:9a (VMware, Inc.)
总结
我们为什么要更改MAC地址,也许你不希望你的实际MAC地址(物理地址)暴露在公共网络上。另一种情况是,网络管理员可能在网络设备中阻止了一个特定的MAC地址。
1.临时性的修改:
①依次输入以下命令:
/sbin/ifconfig eth0 down/sbin/ifconfig eth0 hw ether 00:0C:29:36:97:20/sbin/ifconfig eth0 upservice network restart
2.永久性的修改:
方法①:
并把类似于1中的②脚本保存在/etc/rc.local中:这一步是起作用的关键步骤
脚本如下:
/sbin/ifconfig eth0 down/sbin/ifconfig eth0 hw ether 00:0C:29:36:97:20/sbin/ifconfig eth0 upservice network restart
方法②:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
添加
MACADDR=00:0C:29:36:97:20
注释掉原来的HWADDR
:wq保存退出。
方法③:
直接编辑 /etc/network/interfaces 文件,在 iface eth0 inet static 后面添加一行:
pre-up ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx(要改成的MAC)编辑interfaces文件
sudo nano /etc/network/interfaces如下所示:
face eth0 inet staticpre-up ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx(要改成的MAC)address 192.168.1.10netmask 255.255.255.0gateway 192.168.1.1重启网卡
sudo /etc/init.d/networking restart注:MAC地址由udev在系统启动时探测网卡并加载,可在以下两个文件中反映出来
/sys/class/net/eth0/address 《Linux就该这么学》 一起学习linx
/etc/udev/rules.d/70-persistent-net.rules —-修改无效,根据硬件自动生成的文件
不过,用ifconfig修改了mac后,
/sys/class/net/eth0/address 的值随即跟着变了;但 /etc/udev/rules.d/70-persistent-net.rules 却没有变,只有在udev探测到硬件发生变化时才会修改这个文件。
linux下修改MAC地址方法一:
1.关闭网卡设备
ifconfig
eth0
down
2.修改MAC地址
ifconfig
eth0
hw
ether
MAC地址
3.重启网卡
ifconfig
eth0
up
方法二:
以上方法一修改后linux重启后MAC又恢复为原来的,为了下次启动时修改后的MAC仍有效,我们可以修改文件file:/etc/rc.d
/rc.sysinit(RedFlag
linux为这个文件,其他版本的linux应该不同)的内容,在该文件末尾加以下内容:
ifconfig
eth0
down
ifconfig
eth0
hw
ether
MAC地址
ifconfig
eth0
up
方法三:
很简单的,只是在./etc/sysconfig/network-scripts/ifcfg-eth0中加入下面一句话:
MACADDR=00:AA:BB:CC:DD:EE
方法四:
linux
下如何更改网卡MAC地址
--------------------------------------------------------------------------------
简单的办法是在/etc/rc.d/rc.sysinit文件中加入那些命令:
ifconfig
eth0
down
ifconfig
eth0
hw
ether
xx:xx:xx:xx:xx:xx
ifconfig
eth0
up
因为这个脚本运行在network之前,所以,MAC跟IP就是对应的
方法五:
linux下的MAC地址更改
首先用命令关闭网卡设备。
/sbin/ifconfig
eth0
down
然后就可以修改MAC地址了。
/sbin/ifconfig
eth0
hw
ether
xxxxxxxxxxx
(其中xx是您要修改的地址)
最后重新启用网卡
/sbin/ifconfig
eth0
up
网卡的MAC地址更改就完成了。
----------------------------------------------------------------------------------
修改/etc/sysconfig/network-scripts/ifcfg-eth0,将HWADDR:xxxxxxxxxxxx,增加MACADDR:XXXXXXXXXXX(伪装的mac地址)
本文出自
网络设计
博客
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)