嵌入式爱好者

systemd设置mac地址

2021-11-26 15:29| 发布者: xhh| 查看: 501| 评论: 0

类目: LS1012A/LS1043A/LS1046A系列产品  >  Ubuntu     文档编号: 569

使用命令行配置mac地址再开机时,配置信息会丢失,以下方法用于设置后保存到系统,再次开机时依然生效。

1MAC地址设置

在此介绍一种使用 systemd 方式创建服务的方式来开机自动修改MAC地址的方法。

执行如下命令创建一个脚本文件:

root@forlinx:~# touch mac.sh

root@forlinx:~# vi mac.sh

//写入如下内容

#!/bin/sh

ifconfig swp0 hw ether c2:b6:98:52:c9:c5

ifconfig swp1 hw ether dc:b6:98:52:c9:88

ifconfig swp2 hw ether b2:b6:98:52:46:c4

ifconfig swp3 hw ether e6:02:7f:60:d1:57

修改权限:

root@forlinx:~# chmod 777 mac.sh

创建一个设置mac的服务文件

root@forlinx:~# touch /etc/systemd/system/mac.service

root@forlinx:~# vi /etc/systemd/system/mac.service

//写入如下内容

[Unit]

Description=MAC

After=basic.service X.service thermal-zone-init.service

[Service]

ExecStart=/root/mac.sh

[Install]

WantedBy=multi-user.target

其中 Description 一行需写入服务名,ExecStart 需要写入可执行文件的绝对路径。

保存退出后,在终端上执行如下命令:

root@forlinx:~# systemctl enable /etc/systemd/system/mac.service

Created symlink /etc/systemd/system/multi-user.target.wants/mac.service /etc/systemd/system/mac.service.

此时即可将新添加的自启动服务生效,重启开发板后,此程序即可自动运行,在命令行使用ifconfig -a命令查看swp0网卡信息,会发现MAC地址发生了改变

已解决

未解决

只是看看

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-5-7 21:26

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部