ubuntu20.04修改mac地址 您所在的位置:网站首页 mac地址可以更改么 ubuntu20.04修改mac地址

ubuntu20.04修改mac地址

2023-08-25 13:19| 来源: 网络整理| 查看: 265

暂时修改,开机启动恢复原样

sudo ifconfig enp2s0 down sudo ifconfig enp2s0 hw ether 70:B5:E8:2E:6F:C2 sudo ifconfig enp2s0 up

———————————————————————————————————— 永久修改mac地址,开机后不恢复 *注意:此时是在操作系统文件,先修改为管理员:

sudo su #开启管理员模式 exit #退出管理员模式,更改后需要退出

1、到/lib/systemd/system目录下,使用gedit打开rc-local.service:

cd /lib/systemd/system #到此目录下 ls |grep rc #检查是否有rc开头的文件,正常应该是rc-local.service gedit rc-local.service #打开此文件

文件内容如下:

# SPDX-License-Identifier: LGPL-2.1+ # # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if /etc/rc.local is executable. [Unit] Description=/etc/rc.local Compatibility Documentation=man:systemd-rc-local-generator(8) ConditionFileIsExecutable=/etc/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no

启动文件需要三个部分:

[Unit]段: 启动顺序与依赖关系 [Service] 段: 启动行为,如何启动,启动类型 [Install] 段: 定义如何安装这个配置文件,即怎样做到开机启动

缺少了[Install]块,将其复制粘贴到文件中。

[Install] WantedBy=multi-user.target Alias=rc-local.service

保存并退出。

2、进入/etc/创建rc.local文件,并修改,保存

touch /etc/rc.local

在 /etc/systemd/system 目录下创建软链接

sudo ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/

修改rc.local文件:

#!/bin/sh -e sudo ifconfig enp2s0 down sudo ifconfig enp2s0 hw ether 70:B5:E8:2E:6F:C2 sudo ifconfig enp2s0 up exit 0

注意此处的网卡设备名称enp2s0需要通过ifconfig 来查看:(下图为eth0) 在这里插入图片描述

给rc.local加可执行权限:

sudo chmod +x /etc/rc.local

启动服务并检查服务状态:

sudo systemctl enable rc-local sudo systemctl start rc-local.service sudo systemctl status rc-local.service

参考链接: Ubuntu18.04设置开机启动项并永久修改MAC地址



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有