为CentOS虚拟机添加第二块网卡

简介:

使用virt-install安装了一个CentOS虚拟机,安装过程未指定网络参数,默认使用内置虚拟NAT的方式上网,现在希望给虚拟机另外安装一块虚拟的网卡,然后给其分配一个外网IP地址(与宿主机处于同一网段)。

安装CentOS

$ sudo virt-install --connect qemu:///system --noautoconsole \
-n centos -r 4096 --vcpus=4 --arch=x86_64 --os-type=linux \
--os-variant=rhel6 --accelerate -v -l http://mirrors.163.com/centos/6.3/os/x86_64/ \
--disk path=/var/lib/libvirt/images/centos.img,size=200 \
--graphics vnc,password=foobar,listen=0.0.0.0,port=5901

为宿主机添加虚拟网桥

$ vim /etc/network/interfaces

修改如下

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
iface em1 inet manual

auto br0
iface br0 inet static
    bridge_ports    em1
    bridge_stp  on
    bridge_maxwait  0
    bridge_fd   0
    address     192.168.18.130
    netmask     255.255.255.0
    network     192.168.18.0
    broadcast   192.168.18.255
    gateway     192.168.18.1
    dns-nameservers 192.168.18.1

添加虚拟网桥配置br0,并且把主网卡em1(大多数情况下主网卡为eth0)配置由dhcp或者static改成manual。

然后重启网络服务

$ sudo service networking restart

为虚拟机添加一张额外的虚拟网卡

首先关闭VM

$ virsh destory centos

然后编辑VM配置文件

$ virsh edit centos

在之后加入如下xml片段

<interface type='bridge'>
  <mac address='00:16:3e:1a:b3:4a'/>
  <source bridge='br0'/>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</interface>

然后保存退出。

启动刚才修改过的VM虚拟节点

$ virsh start centos

为CentOS添加新网卡配置

参看/sys/class/net可以看到新添加的网卡eth1

# ls /sys/class/net/
eth0  eth1  lo

通过ifconfig获得该网卡的MAC地址

# ifconfig eth1
eth1    Link encap:Ethernet  HWaddr 00:16:3E:1A:B3:4A  
        inet addr:192.168.18.210  Bcast:192.168.18.255  Mask:255.255.255.0
        inet6 addr: fe80::216:3eff:fe1a:b34a/64 Scope:Link
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:3343 errors:0 dropped:0 overruns:0 frame:0
        TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000 
        RX bytes:216373 (211.3 KiB)  TX bytes:1364 (1.3 KiB)

执行uuidgen生成一个随机的UUID

# uuidgen
e5281311-f265-4afa-a7e1-4d76718f7de0

然后完事具备只欠东方了,

# cd /etc/sysconfig/network-scripts
# cp ifcfg-eth0 ifcfg-eth1
# vim ifcfg-eth1

结合上面的MAC地址和UUID,修改内容如下

DEVICE="eth1"
BOOTPROTO="dhcp"
HWADDR="00:16:3E:1A:B3:4A"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="e5281311-f265-4afa-a7e1-4d76718f7de0"









本文转自 chengxuyonghu 51CTO博客,原文链接:http://blog.51cto.com/6226001001/1536344,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
Linux 网络安全 数据安全/隐私保护
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 CentOS Linux 9 操作系统保姆级教程(附链接)
161 0
|
15天前
|
Linux 虚拟化
VMware workstation 中centos7虚拟机在nat模式下怎么配置网卡,指定我想要的IP并且可以联网
https://blog.csdn.net/2302_78534730/article/details/132825156?spm=1001.2014.3001.5502
131 0
|
8天前
|
安全 Linux 数据安全/隐私保护
Centos7的虚拟机创建流程
Centos7的虚拟机创建流程
46 6
|
15天前
|
网络协议
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
centos8 网卡 Nmcli(是network的简写 Nmcli)配置网络
15 0
|
1月前
|
关系型数据库 MySQL 数据库
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
40 0
|
2月前
|
Linux 网络安全 虚拟化
putty无法连接centos7虚拟机
putty无法连接centos7虚拟机
27 0
|
3月前
|
Kubernetes Linux 数据安全/隐私保护
k8s安装环境准备:Virtualbox安装CentOS;复制多个CentOS虚拟机
k8s安装环境准备:Virtualbox安装CentOS;复制多个CentOS虚拟机
56 0
|
4月前
|
存储 缓存 网络协议
Proxmox创建CentOS虚拟机
Proxmox创建CentOS虚拟机
94 0
|
存储 关系型数据库 MySQL
CentOS在虚拟机的安装
CentOS在虚拟机的安装
173 0
CentOS在虚拟机的安装
|
Linux
虚拟机安装CentOS
虚拟机安装CentOS详细教程
1089 0