如何防止断开连接后MAC地址改变?

如何防止断开连接后MAC地址改变?

macchanger -A wlp68s0b1我在启动时使用 crontab更改了我的 MAC 地址,

当我断开连接并重新连接时会发生以下情况:

启动后连接时:

rahman@debian:~$ macchanger -s wlp68s0b1
Current MAC:   00:22:31:c6:38:45 (SMT&C Co., Ltd.)
Permanent MAC: 00:00:00:00:00:00 (FAKE CORPORATION)

断开连接后:

rahman@debian:~$ macchanger -s wlp68s0b1
Current MAC:   16:7b:e7:3c:d3:cd (unknown)
Permanent MAC: 00:00:00:00:00:00 (FAKE CORPORATION)

重新连接后:

rahman@debian:~$ macchanger -s wlp68s0b1
Current MAC:   00:00:00:00:00:00 (FAKE CORPORATION)
Permanent MAC: 00:00:00:00:00:00 (FAKE CORPORATION)

等等。每次断开连接时,我都会得到一个不同的随机 MAC 地址,该地址在重新连接时会消失,从而为我提供真实的 MAC 地址。是什么原因导致这种情况以及如何阻止它?

一些输出:

rahman@debian:~$ lspci -nn |grep 14e4
44:00.0 Network controller [0280]: Broadcom Limited BCM4313 802.11bgn Wireless Network Adapter [14e4:4727] (rev 01)
rahman@debian:~$ uname -a
Linux debian 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u5 (2017-09-19) x86_64 GNU/Linux
rahman@debian:~$ sudo ifconfig 
enp0s25: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:24:c0:7b:a8:8b  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xd4800000-d4820000  

enp0s25:avahi: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 169.254.9.109  netmask 255.255.0.0  broadcast 169.254.255.255
        ether 00:24:c0:7b:a8:8b  txqueuelen 1000  (Ethernet)
        device interrupt 20  memory 0xd4800000-d4820000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 9436  bytes 6584515 (6.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9436  bytes 6584515 (6.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp68s0b1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.5  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::6711:9875:eb78:24fc  prefixlen 64  scopeid 0x20<link>
        inet6 fd9c:c172:b03b:ce00:f1e0:695e:7da0:91a  prefixlen 64  scopeid 0x0<global>
        ether 00:00:00:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 484346  bytes 641850809 (612.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 368394  bytes 44259668 (42.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

rahman@debian:~$ sudo iwconfig 
lo        no wireless extensions.

enp0s25   no wireless extensions.

wlp68s0b1  IEEE 802.11  ESSID:"3bdo"  
          Mode:Managed  Frequency:2.447 GHz  Access Point: 9C:C1:72:B0:3B:D4   
          Bit Rate=65 Mb/s   Tx-Power=30 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=54/70  Signal level=-56 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:4  Invalid misc:183   Missed beacon:0

答案1

NetworkManager 将在 Wi-Fi 扫描期间重置您的 MAC 地址。

要永久更改您的 MAC 地址:

编辑你的/etc/NetworkManager/NetworkManager.conf如下:

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no

[keyfile]

/etc/network/interfaces通过添加以下行来编辑您的:

pre-up ifconfig wlp68s0b1 hw ether xx:xx:xx:yy:yy:yy

xx:xx:xx:yy:yy:yy从 的输出中获得的新 MAC 地址macchanger -A wlp68s0b1

重新启动并验证您的设置。

配置 MAC 地址随机化在 Arch Linux wiki 中:

默认情况下启用 Wi-Fi 扫描期间的随机化,但可以通过添加以下行/etc/NetworkManager/NetworkManager.conf或在下面添加专用配置文件来禁用它/etc/NetworkManager/conf.d

[device]
wifi.scan-rand-mac-address=no

将其设置为yes会导致在探测无线网络时使用随机生成的 MAC 地址。

答案2

如果其他方法无法解决问题,可以尝试编辑/etc/NetworkManager/conf.d/30-randomize-mac-address.conf

[connection-mac-randomization]
ethernet.cloned-mac-address=permanent
wifi.cloned-mac-address=permanent 

并保留wifi.scan-rand-mac-address=no.

选项有:

  • 永久:使用硬件MAC
  • 保留:激活后不要更改设备的 MAC 地址。
  • random:每次连接时生成一个随机值。
  • stable:生成稳定的哈希 MAC 地址。

答案3

首次安装 macchanger 时,您可以选择在每次新连接时自动更改 MAC 地址。因为我在 --help 页面上没有看到该选项,所以我建议卸载并重新安装。是/否选项会突然出现,询问您是否希望它随机化等等。只需选择“否”,您应该可以从那里顺利航行。

相关内容