启用随机分配 MAC 地址功能时,Android 默认使用永久性随机分配类型。Android 会根据网络配置文件的参数(包括适用于 Passpoint 网络的 SSID、安全类型或 FQDN)生成随机分配的 MAC 地址。在恢复出厂设置之前,此 MAC 地址将保持不变。如果用户忘记并重新添加 WLAN 网络,则不会重新随机分配 MAC 地址,因为所分配的 MAC 地址取决于网络配置文件的参数。
如果网络依赖 MAC 地址的永久性为用户提供有用的功能(例如,记住设备并使用户按照预期绕过登录屏幕),则必须使用永久性 MAC 地址或启用家长控制功能。
对于 Android 10 和 11,框架会在启用随机分配 MAC 地址功能后对所有网络使用永久性随机分配。
非永久性随机分配
在 Android 12 或更高版本中用于某些网络的非永久性随机分配类型下,WLAN 模块在每次连接开始时重新随机分配 MAC 地址,或者框架使用现有的随机分配 MAC 地址连接到网络。在以下情况下,WLAN 模块会重新随机分配 MAC 地址:
DHCP 租约已过期,自设备上次与此网络断开连接的时间已超过 4 小时。
当前网络配置文件的随机分配的 MAC 地址是在 24 小时之前生成的。重新随机分配 MAC 地址仅在新连接开始时执行。WLAN 不会出于重新随机分配 MAC 地址的目的主动断开连接。
如果上述情况均不适用,该框架会使用之前随机选择的 MAC 地址连接到网络。
用于非永久性随机分配的开发者选项
对于搭载 Android 11 或更高版本的设备,用户可以通过开发者选项界面对所有启用了随机分配 MAC 地址功能的 Wi-Fi 网络在全球范围内启用非永久性随机分配 MAC 地址功能。您可以在设置 > 开发者选项 > WLAN 非持久随机分配 MAC 地址功能中找到为所有配置文件启用非永久性随机分配 MAC 地址的选项。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-27。"],[],[],null,["# MAC randomization behavior\n\nThe MAC randomization feature lets devices use a randomized MAC address\nwhen connecting to a Wi-Fi network. For implementation instructions, see\n[Implement MAC randomization](/docs/core/connect/wifi-mac-randomization).\nThis page describes the behavior of MAC randomization in Android.\n\nMAC addresses are used by devices when connecting to a Wi-Fi network\nor an access point. Because these MAC addresses are transmitted without\nencryption, they can be captured and used to potentially track a user's\nlocation. Historically, devices use the *factory MAC address* to associate to\na Wi-Fi network. The factory MAC address is globally unique and static, letting\nthe device be tracked and individually identified.\n\nThe MAC randomization feature increases user privacy by using a randomized MAC\naddress when connecting to a Wi-Fi network.\n\nMAC addresses are 48 bits long and usually represented by 12 hex digits\n(6 octets as each octet is 8 bits) such as `00:11:22:AA:BB:CC`. The MAC\nrandomization feature randomizes the address by setting the *locally\nadministered* bit to 1, and the *unicast* bit to 0. The other 46 bits are\nrandomized.\n\nFor devices running Android 10 or higher, the framework uses randomized MAC\naddress by default. Users can enable or disable MAC randomization for individual\nnetworks through an option in the **Network details** screen in **Settings**,\nas shown in Figure 1. If a user disables MAC randomization for a network, the\nframework uses the factory MAC address (globally unique address).\n\n**Figure 1.** MAC randomization option.\n\nMAC randomization types\n-----------------------\n\nThe Android framework uses two types of MAC randomization:\n[*persistent randomization*](#persistent) and\n[*non-persistent randomization*](#non-persistent). If the user\ndisables MAC randomization, the factory MAC address is used.\n\nAndroid determines which MAC randomization type to use when the device\nassociates to a Wi-Fi network. By default, Android uses persistent\nrandomization. Starting in Android 12, Android\nuses non-persistent randomization in the following situations:\n\n- A network suggestion app specifies that non-persistent randomization be used for the network through the [`WifiNetworkSuggestion.Builder#setMacRandomizationSetting`](https://developer.android.com/reference/android/net/wifi/WifiNetworkSuggestion.Builder#setMacRandomizationSetting(int)) API.\n- The network is an open network that hasn't encountered a captive portal and the `config_wifiAllowEnhancedMacRandomizationOnOpenSsids` overlay is set to `true`. This overlay is disabled (set to `false`) by default.\n\n| **Note:** The Network Details settings screen does not let users control what MAC randomization type is used. Users are only able to enable and disable the MAC randomization feature as a whole for a given network.\n\n### Persistent randomization\n\nAndroid uses the persistent randomization type by default when the MAC\nrandomization feature is enabled. Android generates a persistent randomized MAC\naddress based on the parameters of the network profile including SSID, security\ntype, or FQDN (for Passpoint networks). This MAC address remains the same until\nfactory reset. The MAC address does **not** get re-randomized if the user\nforgets and re-adds the Wi-Fi network since the MAC addressed depends on the\nparameters of the network profile.\n\nPersistent MAC addresses are necessary in cases where networks rely on the\npersistence of the MAC address to provide useful functionality to the user, for\nexample, to remember a device and let users bypass the login screen as\nexpected, or to enable parental controls.\n\nFor Android 10 and 11, the framework uses persistent randomization for all\nnetworks when MAC randomization is enabled.\n\n### Non-persistent randomization\n\nUnder the non-persistent randomization type, which is used for some networks in\nAndroid 12 or higher, the Wi-Fi module re-randomizes\nthe MAC address at the start of every connection or the framework uses the\nexisting randomized MAC address to connect to the network. The Wi-Fi module\nre-randomizes the MAC address in the following situations:\n\n- The DHCP lease duration has expired and more than 4 hours have elapsed since the device last disconnected from this network.\n- The current randomized MAC for the network profile was generated more than 24 hours ago. MAC address re-randomization only happens at the start of a new connection. Wi-Fi won't actively disconnect for the purpose of re-randomizing a MAC address.\n\nIf none of these situations apply, the framework uses the previously randomized\nMAC address to connect to the network.\n\nDeveloper option for non-persistent randomization\n-------------------------------------------------\n\nFor devices running Android 11 or higher, users can enable\nnon-persistent MAC randomization globally for all Wi-Fi networks (that have MAC\nrandomization enabled) through the\n[developer options](https://developer.android.com/studio/debug/dev-options)\nscreen. The option to enable non-persistent MAC randomization for all profiles\nis found at **Settings \\\u003e Developer Options \\\u003e Wi-Fi non-persistent MAC\nrandomization**.\n\n**Figure 2.** Wi-Fi non-persistent MAC randomization option."]]