在 Debian 系统中修改 MAC 地址,常见做法有以下几种(临时修改和永久修改)。
ip 命令(推荐)# 1. 关闭网卡
sudo ip link set dev eth0 down
# 2. 修改 MAC 地址
sudo ip link set dev eth0 address 00:11:22:33:44:55
# 3. 启动网卡
sudo ip link set dev eth0 up
✅ 优点:简单、无需安装额外软件
❌ 缺点:重启后失效
ifconfig(旧方式)sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up
⚠️ ifconfig 已逐渐被 ip 替代,不推荐新系统使用。
/etc/network/interfaces(传统方式)编辑配置文件:
sudo nano /etc/network/interfaces
示例(假设网卡是 eth0):
auto eth0
iface eth0 inet dhcp
hwaddress ether 00:11:22:33:44:55
重启网络:
sudo systemctl restart networking
或重启系统。
nmcli connection show
nmcli connection modify eth0 802-3-ethernet.cloned-mac-address 00:11:22:33:44:55
nmcli connection down eth0
nmcli connection up eth0
✅ 推荐用于使用 NetworkManager 的系统
编辑或新建配置文件:
sudo nano /etc/systemd/network/10-eth0.link
内容示例:
[Match]
MACAddress=原来的MAC地址
[Link]
MACAddress=00:11:22:33:44:55
重启服务:
sudo systemctl restart systemd-networkd
临时随机生成:
sudo macchanger -r eth0
安装:
sudo apt install macchanger
如果你愿意,可以告诉我:
我可以给你最合适的一种方案。