网络接口之间的路由Ubuntu
我想将我的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,反之亦然?
除非有路由器,否则无法从一个网络到达另一个网络。 IP转发适用于传入数据包,并使您的机器成为路由器。我的建议是,与另一台机器连接设备,回用两个接口
机1的eth0(192.168.0.8)<备份 - >机2的eth0(192.168.0.9)
机1的eth1(10.11。 >机器2 eth1(10.11.131.13)
启用两台网络之间的机器2中的IP转发,您可以在两个方向上ping网络。
您的观察结果仅基于'ping -I'命令的输出。但它看起来像是在两种目标位于同一个盒子的情况下,不能正确使用作为源提及的接口。
我有完全相同的环境,Linux主机在两个NIC网络之间转变为路由器。尽管路由功能正常工作,但接口之间的'ping -I'也不成功。此选项还需要IP地址:
-I interface; 接口可以是地址,也可以是接口名称。
并指定作为源不同的NIC的IP地址 - 一切正常。我可以看到,在你的环境中,这也是事实。当您尝试使用罗作为源平提的是,坪的一个仍在两个以太网卡之间运行:
$ 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
另一个问题是,你的配置。看起来你已经在不同的时间点拍摄了它。您在答复中提到:
我的目标是把我的Ubuntu成与192.168.0.0/24连接10.0.0.0/8 路由器。
为此目标,您的路由表是正确的,但是/ etc/network/interfaces文件告诉不同。你应该好好打扫一下了一点 - 删除重复的网关,DNS和路由表项,仅仅是这样的:
# 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
# Here you have 192.168.0.0/24 directly connected, so no need to add route
# ETH1
auto eth1
iface eth1 inet static
address 10.11.131.12
netmask 255.0.0.0
broadcast 10.255.255.255
up route add -net 10.0.0.0/8 gateway 10.11.131.1 eth1
所以试图通过位于本地网络中的一个设备通过设置进行现场测试,达到另一个,当然它的网关作为这个Linux主机的IP地址。
我的目标是将我的Ubuntu变成一个连接10.0.0.0/8与192.168.0.0/24的路由器。我可能需要最终配置NAT,但在设置NAT之前,我应该能够在接口之间进行ping操作。 – Ljung
在这种情况下,您的配置应该工作。由于您的机器设置了IP转发功能,因此当数据包到达时,您的机器将路由并将其发送到另一个接口,并最终出来。但是,当您从eth1 ping eth0时,您的数据包不会通过您的路由器(IP转发模块)而是通过线路传输。 – Deepaklal
它可以作为路由器使用!谢谢! – Ljung