【Linux】修改 MAC 地址

Posted by 西维蜀黍 on 2020-06-20, Last Modified on 2021-09-21

Linux

获取mac地址

$ ip link show
enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
 link/ether 08:xx:xx:xx:xx:x1 brd ff:ff:ff:ff:ff:ff

或者:

$ ifconfig | grep HWaddr
enp0s3    Link encap:Ethernet  HWaddr 08:xx:xx:xx:xx:x1

修改mac地址

Temporary Modification

ifconfig

This involves taking the network interface down, running a command to change its MAC address, and then bringing it back up. Be sure to replace “eth0” with the name of the network interface you want to modify and enter the MAC address of your choice:

$ sudo ifconfig eth0 down

$ sudo ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx

$ sudo ifconfig eth0 up

$ ifconfig eth0 | grep HWaddr

As on Linux, this change is temporary and will be reset when you next reboot. You’ll need to use a script that automatically runs this command on boot if you’d like to permanently change your Mac address.

ip

# First, turn off the Network card using command:
$ sudo ip link set dev [interface] down

# Next, set the new MAC is using command:
$ sudo ip link set dev [interface] address XX:XX:XX:XX:XX:XX

# Finally, turn it on back with command:
$ sudo ip link set dev [interface] up

# Now, verify new MAC id using command:
$ ip link show [interface]

Permanent Modification

macchanger

$ macchanger -m 32:ce:cb:3c:63:cd [interface]

$ ip link show eth0

macOS

Run the following command, replacing en0 with your network interface’s name and filling in your own MAC address:

$ sudo ifconfig en0 xx:xx:xx:xx:xx:xx

The network interface will generally be either en0 or en1 , depending on whether you want to configure a Mac’s Wi-Fi or Ethernet interface. Run the ifconfig command to see a list of interfaces if you’re not sure of the appropriate network interface’s name.

Reference