設定Ubuntu作為內部網路路由器

設定Ubuntu作為內部網路路由器

我正在配置一個內部網路使用 Virtual Box 和 4 個虛擬機器。我已經配置了所有介面並搞亂了一點IP轉發IP假面舞會在主機上,這將是路由器

路由器有兩個乙太網路介面:一個連接HostC,另一個連接HostA和HostB。

如果我做錯了什麼主機C能夠 ping 到主機A和B主機A和B無法 ping 到主機C。應該是路由器的設定。

答案1

為了診斷這裡的問題,您確實應該在您的帖子中添加更多信息,為了清楚起見,我將其添加為答案,因為有一些命令可以嘗試診斷此問題,並且很難在評論中閱讀。請在您的路由器上執行這些命令並報告輸出,這將有助於了解您的網路設定和配置並識別問題:

列出接口:

ip link show

列出介面轉送狀態:

sysctl -a | grep forwarding

列出接口位址:

ip addr show
ip -6 addr show

列出防火牆規則:

iptables -L
ip6tables -L

列出 NAT 規則:

iptables -t nat -L
ip6tables -t nat -L

另請檢查路由器本身是否可以到達所有主機:

ping -c4 HostA
ping -c4 HostB
ping -c4 HostC

當然,用主機 IP 位址取代 HostA/B/C,這是一個重要的步驟,因為如果這裡出現問題,那麼需要先解決該問題,然後再嘗試擔心子網路之間的路由。

答案2

ip link show

結果:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:90:2d:e5 brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:d4:ac:c1 brd ff:ff:ff:ff:ff:ff

一切看起來都很好。

sysctl -a |grep forwarding

結果:

net.ipv4.conf.all.forwarding = 1 net.ipv4.conf.all.mc_forwarding = 0 net.ipv4.conf.default.forwarding = 1 net.ipv4.conf.default.mc_forwarding = 0 net.ipv4.conf.eth0.forwarding = 1 net.ipv4.conf.eth0.mc_forwarding = 0 net.ipv4.conf.eth1.forwarding = 1 net.ipv4.conf.eth1.mc_forwarding = 0 net.ipv4.conf.eth2.forwarding = 1 net.ipv4.conf.eth2.mc_forwarding = 0 net.ipv4.conf.lo.forwarding = 1 net.ipv4.conf.lo.mc_forwarding = 0 net.ipv6.conf.all.forwarding = 0 net.ipv6.conf.all.mc_forwarding = 0 sysctl: reading key "net.ipv6.conf.all.stable_secret" net.ipv6.conf.default.forwarding = 0 net.ipv6.conf.default.mc_forwarding = 0 sysctl: reading key "net.ipv6.conf.default.stable_secret" net.ipv6.conf.eth0.forwarding = 0 net.ipv6.conf.eth0.mc_forwarding = 0 sysctl: reading key "net.ipv6.conf.eth0.stable_secret" net.ipv6.conf.eth1.forwarding = 0 net.ipv6.conf.eth1.mc_forwarding = 0 sysctl: reading key "net.ipv6.conf.eth1.stable_secret" net.ipv6.conf.eth2.forwarding = 0 net.ipv6.conf.eth2.mc_forwarding = 0 sysctl: reading key "net.ipv6.conf.eth2.stable_secret" net.ipv6.conf.lo.forwarding = 0 net.ipv6.conf.lo.mc_forwarding = 0 sysctl: reading key "net.ipv6.conf.lo.stable_secret"

已啟用轉送。

ip addr show

IP位址沒問題。在 Cisco Packet Tracer 中檢查。

ip -6 addr show

未配置 ipv6。

iptables -L

結果:

`鏈輸入(策略接受)目標 prot opt 來源目的地

鏈 FORWARD(策略接受)目標 prot opt 來源目的地

鏈輸出(策略接受)目標 prot opt 來源目的地`

iptables -S

結果:

-P INPUT ACCEPT -P FORWARD ACCEPT -P OUTPUT ACCEPT

現在預設。

Pinging

HostR(路由器,10.0.0.1,172.16.0.1)可以 ping 通 HostA、HostB,但無法 ping 通 HostC

HostA/HostB (10.0.0.5/.6) 可以 ping 到 HostA/B、HostR,但無法 ping 到 HostC

HostC (172.16.0.2) 對所有主機執行 ping 操作。

謝謝您的回答。請告訴我您對這些結果的看法。我現在正在努力處理它。如果有任何突破我會報告。

相關內容