Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9300752
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类:

2012-07-17 11:34:33

Fedora KVM Networking  

2011-08-16 23:53:11|  分类: 虚拟化+云计 |  标签: |字号 

這幾天在自己電腦上安裝了 fedora 15 除了感受一下 gnome3 嶄新的使用者界面外,

順便也玩一下整合很完整的 KVM,用 dvd 裝完以後有勾選虛擬化,就會把相關軟體一次都裝好了(kvm,qemu,libvirtd…) ,

只要透過虛擬機管理員就可以輕鬆的建立 vm,並且使用了~感覺很愜意呢~

只是想要瞭解他相關網路的設定,好像就沒有很簡單了…原本網路概念就有一點模糊,順便重新整理自己網路的知識…

Linux Networking

Linux 可以當作 Router , Switch(bridge) 來使用,當成 Router 來使用之前遇到的情況是使用

iptables 來建立一個 hdcp+nat 的區域網路,透過一台電腦來 forwarding 一整個內網的封包到另外一個界面,

架設在 vmware 的環境,之前應該有一篇文章有寫過哩~

然後 switch 之前就沒用過了,所以不曉得在 linux 內要怎麼使用,這次順便有學到一點…

Linux bridge
先安裝相關工具再來學…怎麼用~

1
2
3
4
# install bridge utils 有指令 brctl 可以用
$ yum install bridge-utils
# install User-mode Linux (utility) 有些工具可以用 主要是 tunctl 可以製作虛擬介面(nic)
$ yum install uml-utilities

然後就可以開始玩~bridge 了

01
02
03
04
05
06
07
08
09
10
11
12
# show all bridge stauts
$ brctl show
 
# add bridge
$ brctl addbr br0
 
# add interface to br0
$ brctl addif br0 eth0
$ brctl addif br0 eth1
 
# remove interfece from br0
$ brctl delif br0 eth0

也可以用 tunctl 增加一些 tap(虛擬網卡),用來加進去 bridge ,在真實 KVM 情況就是用這些虛擬網卡來對應 VM 的網卡的。

01
02
03
04
05
06
07
08
09
10
11
12
13
# add tap0  and tap1
 $ tunctl -t tap0 -u user -g user
 $ tunctl -t tap1 -u user -g user
  
 # create bridge and  add taps
 $ brctl addbr mybr
 $ brctl addif mybr tap0
 $ brctl addif mybr tap1
 # show staus
 $ brctl show
bridge name bridge id       STP enabled interfaces
mybr        0000.002421e18258   no      tap0
                            tap1

ㄜ應該蠻好玩的吧~

然後我建立一個環境來測試一些網路佈署的情況~

我有一個真實的網卡 eth0,有兩台 VM 各有一張網卡,我想要一個可以透過分享實體網卡設定實體IP上網,

另外一台可以透過主機的的 iptables 作 forwarding NAT 上網~

所以我需要兩個 bridge ,一個橋接真實網卡與虛擬網卡,另外一個是純虛擬 bridge 橋接虛擬網卡,

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
# 大略網路資訊
$ ifconfig
eth0
vnet0
vnet1
switch
nat-br
 
# 建立兩個 bridge
$ brctl addbr switch
$ brctl addbr nat-br
 
# 把實體網卡跟虛擬網卡榜在一起
$ brctl addif switch eth0
$ brctl addif switch vnet0
 
# 把 vnet1 加到虛擬 switch 中
$ brctl addif nat-br vnet0

然後就讓 libvirtd 位於 /etc/libvirt/qemu/networks/default.xml 的 dhcp 設定檔,

指向 nat-br 這樣 dhcpd 就會往這個介面分配 IP 了,然後再把 iptables 的 forwarding 從 nat-br 指到 switch ,

vnet1 就可以透過 nat 上網了,

另外要讓 vnet1 可以透過實體 IP 上網,要把 eth0 設成混亂模式,當成對內對外的介面,

然後把 switch 設成實際要上網的 ip,這邊概念還不太清楚,但是這樣確定可以運作 libvirt networking[3]也是這樣寫的~

1
2
3
$ ifconfig eth0 0.0.0.0 promisc
$ ifconfig switch 123.123.123.123 netmask 255.255.255.0
$ route add default gw 123.123.123.126

這樣就能有兩個 bridge,一個區網提供虛擬 IP 讓虛擬機能透過 nat 上網,

另外一個直接跟實體網路銜接,看起來就像跟實體網卡接在同一個 switch 上。

 

 

 

RHEL5.4部署kvm后默认虚拟机联网方式使用nat,可通过手动配置网卡实现桥接(bridge)。
配置桥接网卡br0后物理网卡eth0不需要获得ip地址,其功能被br0取代,因此在配置的时候无论是静态ip还是动态获取都用br0取代eth0,例如桥接前eth0的静态ip是
192.168.0.1那么配置桥接br0的静态ip应为192.168.0.1,而桥接后eth0没有ip
配置步骤(静态IP):
cd /etc/sysconfig/network-scripts/
vi ifcfg-eth0
----------------
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
BRIDGE=br0
----------------
vi ifcfg-br0
----------------
DEVICE=br0
TYPE=Bridge
BOOTPROTO=none
IPADDR=192.168.0.1
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
ONBOOT=yes
---------------
vi /etc/sysctl.conf
---------------------------------------
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
---------------------------------------
iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
services iptables save
service network restart
sysctl -p
services iptables restart
service libvirtd reload
检查桥接网络
brctl show
-------------------------------------------------------
bridge name     bridge id           STP enabled     interfaces
br0             8000.0024549d2950       no              eth0
virbr0          8000.000000000000       yes
---------------------------------------------------------
其中br0是我们配置的桥接网卡,virbr0是系统脚本自动配置的NAT网卡。

阅读(520) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~