一、关闭网卡设备
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