Ubuntu 更改mac地址

來源:互聯網
上載者:User

   一,暫時修改 

     首先必須關閉網卡裝置,否則會報告系統忙,無法更改。

         sudo /sbin/ifconfig eth0 down

    修改 MAC 位址,這一步較 Windows 中的修改要簡單。

        sudo /sbin/ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE (你的MAC地址)

    重新啟用網卡

        sudo /sbin/ifconfig eht0 up

網卡的 MAC 位址更改就完成了



2. 永久修改(兩種方法)
方法一
以上只是暫時修改mac地址,如果需要每次系統啟動後,都自動修改好MAC地址的話,那麼可以將以上命令寫入啟動指令碼中,我使用的方法是將它寫入/etc/init.d/rc.local 的最後。
sudo nano /etc/init.d/rc.local
重啟rc.local

sudo /etc/init.d/rc.local start 

方法二
直接編輯 /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 static
pre-up ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx(要改成的MAC)
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
重啟網卡
sudo /etc/init.d/networking restart


註:MAC地址由udev在系統啟動時探測網卡並載入,可在以下兩個檔案中反映出來
/sys/class/net/eth0/address
/etc/udev/rules.d/70-persistent-net.rules ----修改無效,根據硬體自動產生的檔案
不過,用ifconfig修改了mac後, /sys/class/net/eth0/address 的值隨即跟著變了;但 /etc/udev/rules.d/70-persistent-net.rules 卻沒有變,只有在udev探測到硬體發生變化時才會修改這個檔案。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.