首页 > 网络 > 其他 >

VM,VBOX中CentOS 7 配置网卡-plsql0基础学习笔记-51CTO博客

2020-01-31

我们经常需要复制VM和VBOX的虚拟机,绕不开的一个步骤是网卡的重新配置。有时候这个东西特别繁琐。这里记录一个稍微简单的操作,没有udev的设备绑定各种骚操作。。。 1、 新复制的虚拟机,请选择重新生成MAC地址

我们经常需要复制VM和VBOX的虚拟机,绕不开的一个步骤是网卡的重新配置。有时候这个东西特别繁琐。这里记录一个稍微简单的操作,没有udev的设备绑定各种骚操作。。。

1、 新复制的虚拟机,请选择重新生成MAC地址,这个步骤在复制(克隆,WHATEVER)的时候,或者在复制完成,又或者完成后点配置,网卡属性,高级属性(各种平台各不相同,找到重新生成MAC地址,勾上或者刷新)。记录下这个MAC地址2、新虚拟机启动以后,无论网络是否正常,停掉NetworkManager.Service...真的没有那么好用。systemctl stop NetworkManagersystemctl disable NetworkManager3、运行ifconfig -a, 得到新网卡的网卡名称,(也是设备名称,结合刚才记录下的MAC地址,很容易对上)4、到/etc/sysconfig/network-scripts文件夹修改ifcfg-enxxx网卡启动配置文件4.1、 强烈建议删除ifcfg-profile1类似这个脚本,这个是NetManager遗留。4.2、 用uuidgen enxxx这样的格式得到uuid写入配置档。4.3、 写完配置档,重启网卡设备systemctl restart network。如果没有报错就完成了。

####举例:###配置一个网卡最终要三个要素,设备名,MAC地址,UUID

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.201  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe4a:b12c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:2c  txqueuelen 1000  (Ethernet)
        RX packets 3647  bytes 3417904 (3.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 142  bytes 18249 (17.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno33554992: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.199.241  netmask 255.255.255.0  broadcast 192.168.199.255
        inet6 fe80::20c:29ff:fe4a:b136  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:36  txqueuelen 1000  (Ethernet)
        RX packets 5605  bytes 3465915 (3.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1400  bytes 322360 (314.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

###uuidgen (注意,UUID每次生成都不同,但是每个生成的ID都是可以用的)

[root@mysql01 dev]# uuidgen eno16777736
fd32246b-c655-45c6-ab6a-7a6aa84faa72
[root@mysql01 network-scripts]# uuidgen eno33554992
44e70d2f-4bf1-4753-865b-8fb042ecc8d6
设备名 MAC地址 UUID
eno16777736 00:0c:29:4a:b1:2c fd32246b-c655-45c6-ab6a-7a6aa84faa72
eno33554992 00:0c:29:4a:b1:36 44e70d2f-4bf1-4753-865b-8fb042ecc8d6

###停止NetworkManager

[root@mysql01 network-scripts]# systemctl stop NetworkManager
[root@mysql01 network-scripts]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.

[root@mysql01 network-scripts]# systemctl status NetworkManager
* NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled; vendor preset: enabled)
   Active: inactive (dead) since 日 2020-01-26 14:22:15 CST; 36s ago
 Main PID: 8417 (code=exited, status=0/SUCCESS)

1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  (eno16777736): Activation: successful, device activated.
1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  wpa_supplicant running
1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  (virbr0): device state change: secondaries -> activated (reason 'none...100 0]
1月 26 14:22:07 mysql01 NetworkManager[8417]: <info>  (virbr0): Activation: successful, device activated.
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  caught SIGTERM, shutting down normally.
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  (virbr0): bridge port virbr0-nic was detached
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  (virbr0-nic): released from master virbr0
1月 26 14:22:15 mysql01 systemd[1]: Stopping Network Manager...
1月 26 14:22:15 mysql01 NetworkManager[8417]: <info>  exiting (success)
1月 26 14:22:15 mysql01 systemd[1]: Stopped Network Manager.
Hint: Some lines were ellipsized, use -l to show in full.
[root@mysql01 network-scripts]# ifconfig

###写配置档:(这里的UUID可能和我上面获得的不同,因为配置档是之前就写好的.)-rw-r--r--. 1 root root 292 1月 24 14:52 ifcfg-eno16777736-rw-r--r--. 1 root root 367 1月 26 13:29 ifcfg-eno33554992

[root@mysql01 network-scripts]# cat ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=a808b074-580f-4ff7-b70a-e307769e8d96
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.1.201
PREFIX=24
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

[root@mysql01 network-scripts]# cat ifcfg-eno33554992
TYPE=Ethernet
BOOTPROTO=static
IPADDR0=192.168.199.241
PREFIXO0=24
GATEWAY=192.168.199.1
DNS1=192.168.199.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno33554992
UUID=9c7d8550-2d46-45c1-9c40-ef09570e1608
DEVICE=eno33554992
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes

###重启网络服务:

[root@mysql01 network-scripts]# systemctl restart network.service
[root@mysql01 network-scripts]# 

###没有报错

[root@mysql01 network-scripts]# systemctl status network.service
* network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network)
   Active: active (exited) since 日 2020-01-26 14:27:22 CST; 18s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8612 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
  Process: 8839 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)

1月 26 14:27:17 mysql01 systemd[1]: Starting LSB: Bring up/down networking...
1月 26 14:27:17 mysql01 network[8839]: [29B blob data]
1月 26 14:27:19 mysql01 network[8839]: [37B blob data]
1月 26 14:27:22 mysql01 network[8839]: [37B blob data]
1月 26 14:27:22 mysql01 systemd[1]: Started LSB: Bring up/down networking.
[root@mysql01 network-scripts]# 

###尝试ifup/ifdown脚本:

[root@mysql01 network-scripts]# ifdown eno16777736
[root@mysql01 network-scripts]# ifconfig eno16777736
eno16777736: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:4a:b1:2c  txqueuelen 1000  (Ethernet)
        RX packets 4359  bytes 4215191 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 169  bytes 22144 (21.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 network-scripts]# ifup eno16777736
[root@mysql01 network-scripts]# ifconfig eno16777736
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.201  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe4a:b12c  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:2c  txqueuelen 1000  (Ethernet)
        RX packets 4362  bytes 4218484 (4.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 187  bytes 25011 (24.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 network-scripts]# 
[root@mysql01 network-scripts]# ifdown eno33554992
[root@mysql01 Desktop]# ifconfig eno33554992
eno33554992: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:4a:b1:36  txqueuelen 1000  (Ethernet)
        RX packets 7980  bytes 4516864 (4.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2422  bytes 504771 (492.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 Desktop]# ifup eno33554992
[root@mysql01 Desktop]# ifconfig eno33554992
eno33554992: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.199.241  netmask 255.255.255.0  broadcast 192.168.199.255
        inet6 fe80::20c:29ff:fe4a:b136  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4a:b1:36  txqueuelen 1000  (Ethernet)
        RX packets 7982  bytes 4519567 (4.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2440  bytes 507648 (495.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@mysql01 Desktop]# 

完成

相关文章
最新文章
热点推荐