啟用 MAC 隨機化功能時,Android 預設會使用持續隨機化類型。Android 會根據網路設定檔的參數產生持續隨機 MAC 位址,包括 SSID、安全性類型或 FQDN (適用於 Passpoint 網路)。這個 MAC 位址會維持不變,直到你重設裝置為止。如果使用者忘記並重新加入 Wi-Fi 網路,MAC 位址「不會」重新隨機化,因為 MAC 位址取決於網路設定檔的參數。
如果網路需要依靠 MAC 位址的持久性來為使用者提供實用功能,例如記住裝置並讓使用者如預期略過登入畫面,或啟用家長監護功能,就必須使用持久性 MAC 位址。
針對 Android 10 和 11,當啟用 MAC 隨機化功能時,架構會針對所有網路使用持續隨機化功能。
非持續性隨機
在非持續隨機化類型下 (適用於 Android 12 以上版本的部分網路),Wi-Fi 模組會在每次連線開始時重新隨機化 MAC 位址,或是讓架構使用現有的隨機 MAC 位址連線至網路。Wi-Fi 模組會在以下情況下重新隨機化 MAC 位址:
DHCP 租用期限已到期,且自裝置上次與這個網路中斷連線後,已過超過 4 小時。
網路設定檔目前的隨機 MAC 產生時間超過 24 小時。只有在建立新連線時,系統才會重新隨機產生 MAC 位址。Wi-Fi 不會主動中斷連線,以便重新隨機化 MAC 位址。
如果上述情況皆不適用,架構會使用先前隨機產生的 MAC 位址連線至網路。
非持續性隨機化功能的開發人員選項
如果是搭載 Android 11 以上版本的裝置,使用者可以透過開發人員選項畫面,為所有 Wi-Fi 網路 (已啟用 MAC 隨機產生功能) 啟用全域非持久性 MAC 隨機產生功能。如要為所有設定檔啟用非持續性隨機 MAC 位址,請依序前往「設定」>「開發人員選項」>「Wi-Fi 非持續性隨機 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"]],["上次更新時間:2025-07-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."]]