当前位置:   article > 正文

linux 添加接口永久,linux – 在/ etc / network / interfaces中永久更改Mac地址

linux interface修改mac地址

题:

我怎样才能通过/ etc / network / interfaces文件专门更改enp3s0和wlp2s0接口的Mac地址?我必须在里面包含哪些代码?我已经尝试了一段时间,但没有成功.

阐述:

所以我在网上找到了这篇很棒的文章,解释了如何通过我的Ubuntu上的/ etc / network / interfaces文件永久更改Mac地址.

在文章中,它说:

On Debian, Ubuntu, and similar systems, place the following in the

appropriate section of /etc/network/interfaces (within an iface

stanza, e.g., right after the gateway line) so that the MAC address is

set when the network device is started:

hwaddress ether 02:01:02:03:04:08

现在当我使用以下代码时:

cat /etc/network/interfaces

我得到以下输出

# interfaces(5) file used by ifup(8) and ifdown(8)

auto lo

iface lo inet loopback

当我在我的ubuntu上执行ifconfig时,我会回到3个不同的界面:

> enp3s0

> lo

> wlp2s0

我想更改所有接口的mac地址(enp3s0,wlp2s0)(lo是loopback所以不需要),但我不熟悉/ etc / network / interfaces文件中的命令.我一直在网上看教程,虽然我似乎无法把东西弄好,而且我的电脑甚至开始后几次表现得非常奇怪.

解决方法:

在接口配置块中使用hwaddress ether.例:

auto enp3s0

iface enp3s0 inet static

address 192.0.2.7

netmask 255.255.255.0

gateway 192.0.2.254

hwaddress ether 00:11:22:33:44:55

或者,如果是dhcp:

allow-hotplug enp3s0

iface enp3s0 inet dhcp

hwaddress ether 00:11:22:33:44:55

我错过了一个细节:如果要设置静态IP地址,则hwaddress配置项需要在网关节之后.

但是,如果您在通过网络/接口更改mac时遇到问题,则可以通过udev执行此操作

udev方法 – 使用以下内容创建文件etc / udev / rules.d / 75-mac-spoof.rules:

ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="XX:XX:XX:XX:XX:XX", RUN+="/usr/bin/ip link set dev %k address YY:YY:YY:YY:YY:YY"

你也可以使用systemd单元来完成它,如下所述:Changing mac using systemd units.但是在一天结束时,它们也只是执行ip link set和macchanger的包装器.

标签:mac-address,linux,interface,network-interface

来源: https://codeday.me/bug/20190810/1634815.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/868415
推荐阅读
相关标签
  

闽ICP备14008679号