兩個網路卡之間的路由

兩個網路卡之間的路由

我正在嘗試在不同網路之間路由流量,並遵循我在這裡找到的指南: https://devconnected.com/how-to-add-route-on-linux/

這是一個圖表,我希望它能夠充分描述我正在使用的安排:

Windows 10              Ubuntu                            Linux
172.31.0.X <----------> 172.31.0.33 (eno1)
                        10.0.40.1 (enp2s0f0) <----------> 10.0.40.10

我在 Windows PC 上設定了持久路由,以通過 172.31.0.33 路由 10.0.40.0/24 的任何流量。

路線列印輸出

Ubuntu 電腦設定為透過 10.0.40.1 路由發送至 10.0.40.0/24 的流量。

ip 輸出

從 Ubuntu 計算機 Ping 10.0.40.10 可以正常運作。

如果我從 Windows PC ping 10.0.40.10,我可以看到 ICMP 訊息使用 tcpdump 到達 Ubuntu 電腦上的 172.31.0.33 介面。我在該電腦上的 10.0.40.1 介面上沒有看到任何流量。 Ubuntu 機器似乎沒有按照我的預期路由流量。誰能闡明我錯過了什麼?

新增輸出:

iptables -S

對於 Ubuntu 機器:

sudo iptables -S
# Warning: iptables-legacy tables present, use iptables-legacy to see them
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A FORWARD -i eno1 -j ACCEPT
-A FORWARD -i enp2s0f0 -j ACCEPT
adi@LabBuildServer:~$ sudo iptables-legacy -S
[sudo] password for adi:
-P INPUT ACCEPT
-P FORWARD DROP
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-ISOLATION-STAGE-1
-N DOCKER-ISOLATION-STAGE-2
-N DOCKER-USER
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -o br-e925d11be2da -m conntrack --ctstate RELATED,ESTABLISHED -j ACCE                         PT
-A FORWARD -o br-e925d11be2da -j DOCKER
-A FORWARD -i br-e925d11be2da ! -o br-e925d11be2da -j ACCEPT
-A FORWARD -i br-e925d11be2da -o br-e925d11be2da -j ACCEPT
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -i br-e925d11be2da ! -o br-e925d11be2da -j DOCKER-IS                         OLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -o br-e925d11be2da -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN

輸出:

ip route

在 Linux 主機上:

ip route
default via 10.0.40.1 dev br-POE  proto static
10.0.40.0/24 dev br-POE  proto kernel  scope link  src 10.0.40.10

Ubuntu機器:

adi@LabBuildServer:~$ sudo iptables -t nat -L
[sudo] password for adi:
# Warning: iptables-legacy tables present, use iptables-legacy to see them
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  anywhere             anywhere
MASQUERADE  all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

答案1

解決方案就在那裡:

-P FORWARD DROP

在您的iptables-legacy規則集中,轉送封包的預設原則設定為 DROP,且該規則集中沒有允許將封包轉送至eno1的規則enp2s0f0,僅從橋接介面轉送/轉送至橋接介面...

混合不同的 iptables 總是一個非常糟糕的主意,你應該自己決定是否要使用iptablesiptables-legacy- 每個網路封包都會經歷兩個規則集,導致相當多的混亂。

更新
我的回答不應該意味著你必須安裝預設策略作為接受,我只是指出原因。當然,您可以新增規則以僅允許將流量轉送至這些特定 IP,例如如下所示:

-A FORWARD -i eno1 -s 172.31.0.0/24 -o enp2s0f0 -d 10.0.40.0/24 -j ACCEPT
-A FORWARD -i enp2s0f0 -s 10.0.40.0/24 -o eno1 -d 172.31.0.0/24 -j ACCEPT

相關內容