[問題] 虛擬網卡對外溝通的問題

看板Network作者 (taco)時間15年前 (2009/06/28 12:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 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)
文章代碼(AID): #1AHknJgz (Network)