作者cyu021 (taco)
看板Network
标题[问题] 虚拟网卡对外沟通的问题
时间Sun Jun 28 12:06:42 2009
※ [本文转录自 Linux 看板]
作者: cyu021 (taco) 看板: Linux
标题: [问题] 虚拟网卡对外沟通的问题
时间: Sun Jun 28 12:04:36 2009
各位好,
我想问的问题是,如果一张实体网卡下面的虚拟网介面直接对外丢封包的时候,
封包会经过实体网卡被送到外部去吗?
更详细的描述如下:
我有一张实体网卡eth0,
在eth0下面长了两张虚拟网卡veth0/veth1,
在veth1下面又长了一张支援VLAN的虚拟网卡veth1.11,
其中eth0与veth0存在於同一个网路空间,
veth1与veth1.11存在於另外一个独立的网路空间,做法如下:
[CODE]
1. 开启两个shell(shell-1 & shell0-2)
2. 在shell-1中输入ip link add type veth,这样会建立veth0 & veth1
3. 在shell-2中输入./ns_exec -nm -- /bin/bash,将网路空间独立出来,
这时候执行ifconfig -a将看不到任何网卡
4. 在shell-2中输入echo $$,取得shell-2的PID
5. 在shell-1中输入ip link set veth1 netns [第二个shell的PID],
将veth1分配给网路空间独立後的shell-2使用
6. 在shell-2中输入vconfig add veth1 11,建立支援VLAN的虚拟网卡
ps. 输入git clone git://git.sr71.net/~hallyn/cr_tests.git可以取得ns_exec的
原始码
[/CODE]
网路设置如下:
[CODE]
+--NS1---+ +-NS2-+ +-------------+ +---------------+
|veth1.11| | eth0|---|Switch/Router|---|其他PC/Server @|
| veth1|---|veth0| +-------------+ |10.0.0.x/24 |
+--------+ +-----+ +---------------+
[/CODE]
IP设置如下:
[CODE]
+----- NS1 ---------------------
veth1 --> 192.168.0.101/24
veth1.11 --> 10.0.0.101/24
+-------------------------------
+----- NS2 ---------------------
eth0 --> 192.168.19.148/24
veth0 --> 192.168.0.100/24
+-------------------------------
[/CODE]
Route设置如下:
[CODE]
+----- NS1 ---------------------
192.168.0.0/24 dev veth1 proto kernel scope link src 192.168.0.101
10.0.0.0/8 dev veth1.11 proto kernel scope link src 10.0.0.101
+-------------------------------
+----- NS2 ---------------------
[root@vmf11 ~]# ip route
192.168.19.0/24 dev eth0 proto kernel scope link src 192.168.19.148 metric 1
192.168.0.0/24 dev veth0 proto kernel scope link src 192.168.0.100
default via 192.168.19.2 dev eth0 proto static
+-------------------------------
[/CODE]
[b][color=red]如果今天NS1发出封包给NS2,直接由veth0被往外丢而没有经过eth0,
也就是说用tcpdump看eth0与veth0时,只有veth0有反应,
那麽,这些直接从veth0被丢出来的封包会在Switch/Router上出现,
然後被送到其他PC/Server上吗?[/color][/b]
操作过程如下:
[CODE]
+----- NS1 ---------------------
[root@vmf11 MRG]# ping 10.0.0.10
PING 10.0.0.10 (10.0.0.10) 56(84) bytes of data.
+-------------------------------
+----- NS2 ---------------------
[root@vmf11 ~]# tcpdump -ne -i veth0 not port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on veth0, link-type EN10MB (Ethernet), capture size 96 bytes
11:56:36.797332 da:03:74:87:9c:af > Broadcast, ethertype 802.1Q (0x8100), length 46: vlan 11, p 0, ethertype ARP, arp who-has 10.0.0.10 tell 10.0.0.101
11:56:37.799290 da:03:74:87:9c:af > Broadcast, ethertype 802.1Q (0x8100), length 46: vlan 11, p 0, ethertype ARP, arp who-has 10.0.0.10 tell 10.0.0.101
[root@vmf11 ~]# tcpdump -ne -i eth0 not port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
+-------------------------------
[/CODE]
--
=====================================
| James aka. taco -- |
| War doesn't determine who's right,|
| just who's left. |
| Same to LIFE...?! |
=====================================
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 116.59.166.2
--
=====================================
| James aka. taco -- |
| War doesn't determine who's right,|
| just who's left. |
| Same to LIFE...?! |
=====================================
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 116.59.166.2
※ 编辑: cyu021 来自: 116.59.166.2 (06/28 12:27)