博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centos6.5网络虚拟化技术
阅读量:5092 次
发布时间:2019-06-13

本文共 4669 字,大约阅读时间需要 15 分钟。

一、配置KVM虚拟机NAT网络

 1、创建脚本执行权限

下面是NAT启动脚本

# vi /etc/qemu-ifup-NAT 

 赋予权限

# chmod +x /etc/qemu-ifup-NAT 

下载镜像文件

cirror project:为cliud环境测试vm提供的微缩版linux

镜像名称: cirros-0.3.4-x86_64-disk.img

镜像下载地址:http://download.cirros-cloud.net/0.3.4/

把镜像放到默认位置

# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

# mv cirros-0.3.4-x86_64-disk.img /var/lib/libvirt/images/

通过命令启动虚拟机

 # qemu-kvm -m 1024 -drive file=cirros-0.3.4-x86_64-disk.img,if=virtio -net nic,model=virtio -net tap,script=/etc/qemu-ifup-NAT -nographic -vnc :2 

实验失败,创建的虚拟机登录不进去,启动的时候报错

 

 

二、配置KVM虚拟机Bridge网络

1、安装工具

安装brctl和tunctl命令行工具

# yum install bridge-utils tunctl -y

查看tun模块是否加载

[root@localhost ~]# lsmod | grep tuntun                    17095  2 vhost_net

 

2、创建Bridge

[root@localhost ~]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:2a:09:c7 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.55/24 brd 192.168.1.255 scope global eth0
inet6 fe80::20c:29ff:fe2a:9c7/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 52:54:00:dc:9c:cd brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 500
link/ether 52:54:00:dc:9c:cd brd ff:ff:ff:ff:ff:ff
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# brctl addbr br0
[root@localhost ~]#
[root@localhost ~]# brctl addif br0 eth0

 Xshell断开连接,在主机内部进行操作

网卡配置分别配置如下

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0TYPE=EthernetONBOOT=yesNM_CONTROLLED=noBOOTPROTO=noneDRIDGE=br0[root@localhost ~]# [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0 DEVICE=br0TYPE=bridgeONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticIPADDR=192.168.1.55NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS1=8.8.8.8

 重启网卡配置生效

[root@localhost ~]# service network restartShutting down interface eth0:                              [  OK  ]Shutting down loopback interface:                          [  OK  ]Bringing up loopback interface:                            [  OK  ]Bringing up interface br0:  Determining if ip address 192.168.1.55 is already in use for device br0...                                                           [  OK  ]Bringing up interface eth0:                                [  OK  ]

 

Xshell连接

查看网络信息

[root@localhost ~]# ip addr list1: lo: 
mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0:
mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:2a:09:c7 brd ff:ff:ff:ff:ff:ff inet6 fe80::20c:29ff:fe2a:9c7/64 scope link valid_lft forever preferred_lft forever3: virbr0:
mtu 1500 qdisc noqueue state UNKNOWN link/ether 52:54:00:dc:9c:cd brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr04: virbr0-nic:
mtu 1500 qdisc noop state DOWN qlen 500 link/ether 52:54:00:dc:9c:cd brd ff:ff:ff:ff:ff:ff6: br0:
mtu 1500 qdisc noqueue state UNKNOWN link/ether 00:0c:29:2a:09:c7 brd ff:ff:ff:ff:ff:ff inet 192.168.1.55/24 brd 192.168.1.255 scope global br0 inet6 fe80::20c:29ff:fe2a:9c7/64 scope link valid_lft forever preferred_lft forever

 

查看路由表

[root@localhost ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br0192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0169.254.0.0     0.0.0.0         255.255.0.0     U     1006   0        0 br00.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 br0

 

 查看桥接信息

[root@localhost ~]# brctl showbridge name     bridge id               STP enabled     interfacesbr0             8000.000c292a09c7       no              eth0virbr0          8000.525400dc9ccd       yes             virbr0-nic

 

 查看br0桥

[root@localhost ~]# brctl show br0bridge name     bridge id               STP enabled     interfacesbr0             8000.000c292a09c7       no              eth0

转载于:https://www.cnblogs.com/djlsunshine/p/10270676.html

你可能感兴趣的文章
python 3全栈开发-面向对象之绑定方法(classmethod与staticmethod的区别)、多态、封装的特性property...
查看>>
AIR SDK 更新方法
查看>>
HttpComponents HttpCore 4.3 Alpha1 发布
查看>>
PacketFence ZEN 4.0.1 发布,网络接入控制
查看>>
两个小的java程序,用于练习java基本语法
查看>>
MySql is marked as crashed and should be repaired问题
查看>>
CentOS设置时间
查看>>
java 批量导入图片到excel
查看>>
B树和B+树的总结
查看>>
【ubuntu】配置zsh
查看>>
怎样用通用pe工具箱制作U盘启动盘
查看>>
在ubuntu16.04-32bits 下编译vlc和vlc-qt开源项目
查看>>
转:你真的懂iOS的autorelease吗?
查看>>
Linux学习——磁盘分区管理
查看>>
H5C302
查看>>
给 Android 开发者的 RxJava 详解
查看>>
设计:抽象类类还是接口
查看>>
解决 jsp:include 引用文件时出现乱码的问题
查看>>
712. Minimum ASCII Delete Sum for Two Strings
查看>>
C++ json解析
查看>>