我想將我的Ubuntu變成一個路由器。我想在eth0(192.168.0.0/24)接口和eth1(10.0.0.0/8)接口之間路由流量。我有以下的/ etc /網絡/接口的配置:網絡接口之間的路由Ubuntu
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.8
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8 8.8.4.4
up route add -net 10.74.0.0/16 gateway 10.11.131.1 eth1
# ETH1
auto eth1
iface eth1 inet static
address 10.11.131.12
netmask 255.0.0.0
broadcast 10.255.255.255
gateway 10.11.131.1
dns-nameservers 8.8.8.8 8.8.4.4
up route add -net 8.8.0.0/16 gateway 192.168.0.1 eth0
up route add -net 10.74.0.0/16 gateway 10.11.131.1 eth1
路線-n給我下面的輸出:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use
Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth1
10.74.0.0 10.11.131.1 255.255.0.0 UG 0 0 0 eth1
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
執行cat/proc/SYS /網/的IPv4/IP_FORWARD返回1
我不能eth1的和爲eth0之間平:
$ ping 192.168.0.8 -I eth1
PING 192.168.0.8 (192.168.0.8) from 10.11.131.12 eth1: 56(84) bytes of data.
From 10.11.131.12 icmp_seq=1 Destination Host Unreachable
$ ping 10.11.131.12 -I eth0
PING 10.11.131.12 (10.11.131.12) from 192.168.0.8 eth0: 56(84) bytes of data.
... no response ...
不過,我可以來回ping通兩個以太網接口m回送。
$ ping 10.11.131.12 -I lo
ping: Warning: source address might be selected on device other than lo.
PING 10.11.131.12 (10.11.131.12) from 192.168.0.8 lo: 56(84) bytes of data.
64 bytes from 10.11.131.12: icmp_seq=1 ttl=64 time=0.032 ms
$ ping 192.168.0.8 -I lo
ping: Warning: source address might be selected on device other than lo.
PING 192.168.0.8 (192.168.0.8) from 192.168.0.8 lo: 56(84) bytes of data.
64 bytes from 192.168.0.8: icmp_seq=1 ttl=64 time=0.032 ms
我需要做什麼才能從eth0 ping eth1,反之亦然?
我的目標是將我的Ubuntu變成一個連接10.0.0.0/8與192.168.0.0/24的路由器。我可能需要最終配置NAT,但在設置NAT之前,我應該能夠在接口之間進行ping操作。 – Ljung
在這種情況下,您的配置應該工作。由於您的機器設置了IP轉發功能,因此當數據包到達時,您的機器將路由並將其發送到另一個接口,並最終出來。但是,當您從eth1 ping eth0時,您的數據包不會通過您的路由器(IP轉發模塊)而是通過線路傳輸。 – Deepaklal
它可以作爲路由器使用!謝謝! – Ljung