﻿# 如何變更 Windows 10 實體網路卡的實體位址 (MAC Address)

最近公司有台筆電的實體網卡壞了，因此臨時買了一個有 RJ45 接孔的 USB 網路卡來用，但新的網卡會有新的 MAC 位址，而該筆電所處的網路環境有綁定 IP 與 MAC 地址，因此導致筆電就無法上網了。這篇文章我來說明如何在 Windows 變更新買網卡的 MAC 位址。

### 變更現有網卡的實體位址 (MAC Address)

1.  按下 `Win+R` 開啟「執行」視窗，輸入 `ncpa.cpl` 開啟「網路連線」頁面
    
    ![image](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/65e517cd38f7b3c8bb07-182891871-11dcb860-72e0-4592-b242-7851863bb05e.png)
    
2.  找到實體網卡的網路介面 (Network Interface)，按下滑鼠右鍵，點選「屬性」
    
    ![image](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/06c79c6d63fb1f6db12b-182893076-0039385f-30f2-4fab-8ba9-a08fa9efe008.png)
    
3.  點擊在網路介面卡旁邊的「設定」
    
    ![image](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/0b80f66170ea829bb7e6-182893698-4bd6a0bb-84eb-4bc3-afbd-566457e9d5ea.png)
    
4.  切換至「進階」頁籤，找到「本地管理位址」，點擊輸入欄位左邊的單選按鈕，輸入新的 MAC 位址
    
    ![image](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/a9ec2fb4d31ef2472200-182895385-c7fb25d2-1d18-4a20-9a4b-6d29f53d0cdd.png)
    
    > 注意：這裡的 **本地管理位址** 也有可能顯示 **Network Address** 或 **Locally Administered Address** 喔！
    
    > 老實說，我不得不抱怨一下，這個「本地管理位址」翻譯的還真爛，完全聯想不到是 Network Address 的意思！
    
5.  最後按下 `OK` 按鈕，就會自動套用到網卡上，此時網卡會先停用後自動啟用，網路也會瞬斷幾秒鐘，不用重開機，新的 MAC 位址就會生效了！
    

### 驗證網卡實體位址的方法

1.  使用 `getmac` 命令
    
2.  使用 `ipconfig /all` 命令
    
3.  使用我從[這篇文章](https://richardspowershellblog.wordpress.com/2018/10/13/testing-internet-connectivity/)微調過的 PowerShell 函式
    
    ```powershell
    function Get-InternetConnection {
        $prf = Get-NetConnectionProfile -IPv4Connectivity Internet
    
        $nic = Get-NetAdapter -InterfaceIndex $prf.InterfaceIndex -ErrorAction Ignore
        $ipi = Get-NetIPInterface -InterfaceIndex $prf.InterfaceIndex -ErrorAction Ignore
    
        $ip = $prf | Get-NetIPAddress -AddressFamily IPv4
        $dg = $prf | Get-NetIPConfiguration
        $stat = if ($nic) { if ($nic.InterfaceOperationalStatus -eq 1) { 'Up' } else { 'Down' } }
        $maca = if ($nic) { $nic.MacAddress }
        $props = [ordered]@{
            ConnectionProfile = $prf.Name
            IPv4Connectivity  = $prf.IPv4Connectivity
            IPv6Connectivity  = $prf.IPv6Connectivity
            InterfaceIndex    = $prf.InterfaceIndex
            InterfaceAlias    = $prf.InterfaceAlias
    
            NetAdapter_InterfaceStatus   = $stat
            NetAdapter_InterfaceMacAddr  = $maca
    
            NetIPInterface_ConnectionState = $ipi.ConnectionState
            NetIPInterface_AddressFamily   = $ipi.AddressFamily
    
            IPAddress         = $ip.IPAddress
            SubnetMask        = $ip.PrefixLength
            DefaultGateway    = $dg.IPv4DefaultGateway | Select-Object -ExpandProperty NextHop
            DNSServer         = ($dg.DNSServer).serverAddresses
        }
        New-Object -TypeName PSobject -Property $props
    }
    ```
    
    這個 PowerShell Function 的使用方式如下，非常簡單：
    
    ```powershell
    Get-InternetConnection
    ```
    
    ![Get-InternetConnection](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/4b301525aef85a3addd2-182900937-09dc6ae8-c7b0-46c6-9a82-025b4a073f45.png)
    
    > 這個命令主要會取得目前上網的主要**網路設定檔**(Network Profile)，然後取得該**網路設定檔**的**網卡**與**網路設定**，並且完整的呈現出來。
    

### 相關連結

-   [關於查詢 MAC 位址與 ARP 位址解析協定的兩三事](/post/2022/07/18/How-to-get-MAC-address-and-about-ARP-Protocol)
-   [Testing Internet connectivity | Richard Siddaway's Blog](https://richardspowershellblog.wordpress.com/2018/10/13/testing-internet-connectivity/)
-   [MAC Address Generator Online](https://dnschecker.org/mac-address-generator.php)
-   [NetConnection Module | Microsoft Docs](https://learn.microsoft.com/en-us/powershell/module/netconnection/?view=windowsserver2022-ps&WT.mc_id=DT-MVP-4015686)
    -   [Get-NetConnectionProfile](https://learn.microsoft.com/en-us/powershell/module/netconnection/get-netconnectionprofile?view=windowsserver2022-ps)
    -   [Set-NetConnectionProfile](https://learn.microsoft.com/en-us/powershell/module/netconnection/set-netconnectionprofile?view=windowsserver2022-ps)
-   [NetAdapter Module | Microsoft Docs](https://learn.microsoft.com/en-us/powershell/module/netadapter/?view=windowsserver2022-ps&WT.mc_id=DT-MVP-4015686)
    -   [Get-NetAdapter](https://learn.microsoft.com/en-us/powershell/module/netadapter/get-netadapter?view=windowsserver2022-ps&WT.mc_id=DT-MVP-4015686)
-   [NetTCPIP Module | Microsoft Docs](https://learn.microsoft.com/en-us/powershell/module/nettcpip/?view=windowsserver2022-ps&WT.mc_id=DT-MVP-4015686)
    -   [Get-NetIPInterface](https://learn.microsoft.com/en-us/powershell/module/nettcpip/get-netipinterface?view=windowsserver2022-ps&WT.mc_id=DT-MVP-4015686)
