# 網路流量除錯規劃
## 相關手法
* 截圖

* echo 2

## 蒐集資料
- [x] 1. 打開 VPC flow log
- [x] 2. 蒐集升級雲的網卡資訊
* 備註:確認使用中的內網 IP
* `88.249.37.241` (SDN)
* GW: `88.249.36.1`
> 已蒐集升級雲、行內 MongoDB,皆只有一張網卡配置「Intranet」(內部網路)
> 該 「88開頭」之 IP 為行內之軟體定義網路
- [x] 3. 蒐集行內 MongoDB 網卡資訊
* 備註:確認使用中的內網 IP
> 同上,僅有 Intranet IP
- [x] 4. 蒐集 Outposts MongoDB EC2 網卡資訊
- [x] 5. 蒐集 Outposts Worker Node EC2 網卡資訊
## 雲上 IP 配置一覽

## VPC Flow Log
* 參考 [使用 Athena 快速的查找 AWS VPC Flow Log 方式](https://hackmd.io/WACqLmz8QvqQE0ANNeO0cg) 一文做法
* 由先前蒐集到的 logs 匯入 Glue 的 Table,並取名為 `vpc_flow_logs_20221229`
```sql=
CREATE EXTERNAL TABLE IF NOT EXISTS vpc_flow_logs_20221229 (
version int,
account string,
interfaceid string,
sourceaddress string,
destinationaddress string,
sourceport int,
destinationport int,
protocol int,
numpackets int,
numbytes bigint,
starttime int,
endtime int,
action string,
logstatus string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ' '
LOCATION 's3://mylog-cloudwatch/logs_20221229/'
TBLPROPERTIES ("skip.header.line.count"="1");
```
### 找從不同網段送給 compute node 的流量
* 從上述表格撈取資料
* 過濾那些要「傳給 10.200.16.88」的流量
* 並且選擇來源「不是來自 VPC 內」的流量
```sql=
SELECT * from vpc_flow_logs_20221229
WHERE "destinationaddress"='10.200.16.88'
AND "sourceaddress" NOT LIKE '10.200.16.%'
ORDER BY "sourceaddress" ASC;
```
* 從下面表格可以看出送給 `10.200.16.88` 的流量的來源IP,以及分別來自兩個介面
| 來源 IP | interface_id | 目標 IP |
| -------- | -------- | -------- |
| 10.200.18.106 | eni-04786fb06ba4f033d | 10.200.16.88 |
| 10.200.18.106 | eni-037ab9763f1101f40 | 10.200.16.88 |
| 10.200.18.152 | eni-07835ee5d17a0c1b8 | 10.200.16.88 |
| 10.200.18.152 | eni-04786fb06ba4f033d | 10.200.16.88 |
| 10.200.18.191 | eni-04786fb06ba4f033d | 10.200.16.88 |
| 10.200.18.191 | eni-0758bdafeecbb4ebb | 10.200.16.88 |
| 10.200.18.32 | eni-04075854a76a8496c | 10.200.16.88 |
| 10.200.18.32 | eni-04786fb06ba4f033d | 10.200.16.88 |
> 以及其他非 10 開頭之 IP,請參考貼圖


### 找是否有進到 VPC 後、被 compute node 拒絕的量量
* 另外再檢查傳送給 10.200.16.88 的流量,皆未被 REJECT
```sql=
SELECT * from vpc_flow_logs_20221229
WHERE "destinationaddress"='10.200.16.88'
AND "action" LIKE 'REJECT%';
```

### 計算,送給 compute node 的流量來源排行
```sql=
SELECT "sourceaddress", COUNT(*) from vpc_flow_logs_20221229
WHERE "destinationaddress"='10.200.16.88'
AND "sourceaddress" NOT LIKE '10.200.16.%'
GROUP BY "sourceaddress"
ORDER BY COUNT(*) DESC;
```
