ubuntu18.04修改mac地址

本文档介绍了如何在Ubuntu 18.04系统中关闭、修改和启用网卡MAC地址,以及如何通过systemd设置开机启动时自动执行修改MAC地址的脚本。主要涉及的命令包括`ifconfig`用于管理网卡状态和MAC地址,以及`systemd`服务配置以实现系统启动时的自动化操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、关闭网卡设备

sudo ifconfig eno1 down

其中eth0是要修改mac地址网卡的名称,并非所有的网卡命名都是按照eth0、eth1来命名的,因此需要查看自己网卡名称,输入命令ifconfig即可查看,本实验eno1。

二、修改MAC地址

sudo ifconfig eno1 hw ether macip

三、重新启用网卡

sudo ifconfig eno1 up

四、系统配置

如果不想每次设置,可以修改下系统配置。ubuntu18.04使用systemd设置开机启动,systemd默认读取/etc/systemd/system下的配置文件,该目录下的文件会链接/lib/systemd/system/下的文件。一般系统安装完/lib/systemd/system/下会有rc-local.service文件。查看/lib/systemd/system/rc-local.service文件:

123@123-optiplex-7071:~$ cat /lib/systemd/system/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
loongson@loongson-optiplex-7071:~$ 

上边有个ConditionFileIsExecutable相关的/etc/rc.local文件,如果该文件不存在,自己创建,并添加开机想执行的脚本,比如我们这里的修改mac地址:

sudo ifconfig eno1 down
sudo ifconfig eno1 hw macip
sudo ifconfig eno1 up

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值