標籤:des style http color io os 使用 ar for
linux Bridge是核心支援的橋接器裝置,可以實現簡單的交換器功能。現在的需求就是想監聽雲平台下,雲主機所有的流量。我們用的是Bridge,沒有使用vswitch這種功能強大的軟體裝置。通過查閱資料
http://backreference.org/2014/06/17/port-mirroring-with-linux-bridges/
http://superuser.com/questions/753294/mirror-port-via-iptables
http://askubuntu.com/questions/22562/copy-all-bridge-traffic-to-a-specific-interface
有以下幾種方式:
iptables
利用iptables來,編輯
mangle table specific
-j ROUTE (explicitly route packets, valid at PREROUTING)
options:
--iface <iface_name>
--ifindex <iface_idx>
也可以直接輸入命令。
iptables –I PREROUTING –t mangle –i eth0 –j TEE –gateway 192.168.200.1
iptables –I POSTROUTING –t mangle –j TEE –gateway 192.168.200.1
文檔上的說明:
The TEE target will clone a packet and redirect this clone to another machine on the local network segment. In other words, the nexthop must be the target, or you will have to configure the nexthop to forward it further if
so desired.
--gateway ipaddr
Send the cloned packet to the host reachable at the given IP address. Use of 0.0.0.0 (for IPv4 packets) or :: (IPv6) is invalid.
To forward all incoming traffic on eth0 to an Network Layer logging box:
-t mangle -A PREROUTING -i eth0 -j TEE --gateway 2001:db8::1
目標是TEE,把資料包複製到另外一個本網機器。但是需要注意到修改是的mangle表,到這一步的時候,資料包其實都已經做過snat dnat,顯然已經不是雲主機原來出來的包了。
tc工具
Daemonlogger
sudo daemonlogger -i <input_interface> -o <mirror_interface>
where the arguments are explained as
-i <interface> Set interface to grab data from to <interface>. -o <interface> Disable logging, instead mirror traffic from -i <interface> to -o <interface>.
這個就很簡單了
小實驗:
在bond0上抓包
tcpdump -i bond0 -n|grep 223.5.5.5tcpdump: WARNING: bond0: no IPv4 address assignedtcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on bond0, link-type EN10MB (Ethernet), capture size 65535 bytes10:51:01.160065 IP 10.10.82.226 > 223.5.5.5: ICMP echo request, id 15978, seq 182, length 6410:51:01.163128 IP 223.5.5.5 > 10.10.82.226: ICMP echo reply, id 15978, seq 182, length 6410:51:02.161217 IP 10.10.82.226 > 223.5.5.5: ICMP echo request, id 15978, seq 183, length 64
在vnet0上抓包
[email protected]:~# tcpdump -i vnet0 -n|grep 223.5.5.5tcpdump: WARNING: vnet0: no IPv4 address assignedtcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on vnet0, link-type EN10MB (Ethernet), capture size 65535 bytes17:31:42.458344 IP 192.168.138.14 > 223.5.5.5: ICMP echo request, id 30953, seq 1, length 6417:31:42.461327 IP 223.5.5.5 > 192.168.138.14: ICMP echo reply, id 30953, seq 1, length 64
可以發現在bridge上vlnet0出來的包都是原生的!也就是沒有經過iptables上網
特別需要注意的是為什麼不是直接匯出bond0上的流量,是因為我們在iptables上做了snat、dnat的規則,具體的參考前面的文章。正是因為有了snat、dnat這樣原來的包已經發生了變化,也就無法更具src或者dest來監視相關的雲主機的流量了。
linux Bridge mirror port