我正在尝试让我的路由在具有 3 个网卡和 3 个子网的 RHEL 7 上运行。
我有以下网卡
DEVICE=eth0
BOOTPROTO=sttic
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPADDR=10.241.78.5
NETMASK=255.255.254.0
IPV6INIT=no
DEVICE=eth1
BOOTPROTO=static
IPADDR=10.241.74.5
NETMASK=255.255.254.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
DEVICE=eth2
BOOTPROTO=static
IPADDR=10.241.76.5
NETMASK=255.255.254.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
ip route show
10.241.74.0/23 dev eth1 proto kernel scope link src 10.241.74.5
10.241.78.0/23 dev eth0 proto kernel scope link src 10.241.78.5
10.241.76.0/23 dev eth2 proto kernel scope link src 10.241.76.5
default via 10.241.78.1 dev eth0
我在 eth1 后面有一个系统 10.241.74.7,在 eth2 后面有一个系统 10.241.76.7
我还设置了 sysctl.conf,内容如下
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
我遇到的问题是 eth1 后面的系统无法到达 eth2,反之亦然。
当我从 .5 系统发起 ping 时
ping 10.241.74.7 -I eth2
PING 10.241.74.7 (10.241.74.7) from 10.241.76.5 eth2: 56(84) bytes of data.
From 10.241.76.5 icmp_seq=2 Destination Host Unreachable
From 10.241.76.5 icmp_seq=3 Destination Host Unreachable
From 10.241.76.5 icmp_seq=4 Destination Host Unreachable
ping 10.241.76.7 -I eth1
PING 10.241.76.7 (10.241.76.7) from 10.241.74.5 eth1: 56(84) bytes of data.
From 10.241.74.5 icmp_seq=2 Destination Host Unreachable
From 10.241.74.5 icmp_seq=3 Destination Host Unreachable
From 10.241.74.5 icmp_seq=4 Destination Host Unreachable
但是,当我从 eth0 ping 两个网络时,它可以工作:
ping 10.241.76.7 -I eth0
PING 10.241.76.7 (10.241.76.7) from 10.241.78.5 eth0: 56(84) bytes of data.
64 bytes from 10.241.76.7: icmp_seq=1 ttl=64 time=0.450 ms
64 bytes from 10.241.76.7: icmp_seq=2 ttl=64 time=0.483 ms
ping 10.241.74.7 -I eth0
PING 10.241.74.7 (10.241.74.7) from 10.241.78.5 eth0: 56(84) bytes of data.
64 bytes from 10.241.74.7: icmp_seq=1 ttl=64 time=0.461 ms
64 bytes from 10.241.74.7: icmp_seq=2 ttl=64 time=0.399 ms
iptables 已被刷新,所以我不确定为什么流量无法在两个网络之间传输...可能存在路由问题?
netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.241.74.0 0.0.0.0 255.255.254.0 U 0 0 0 eth1
10.241.78.0 0.0.0.0 255.255.254.0 U 0 0 0 eth0
10.241.76.0 0.0.0.0 255.255.254.0 U 0 0 0 eth2
0.0.0.0 10.241.78.1 0.0.0.0 UG 0 0 0 eth0
有人可以帮忙吗?
答案1
为了使 Linux 在接口之间转发数据包,您需要设置net.ipv4.ip_forward=1
并/etc/sysctl.conf
重新启动系统以使更改生效,或者运行sysctl -p
关于您的 ping 结果,如果我没记错的话,通过-I ethX
在 ping 命令上指定,您强制数据包实际上从指定的接口离开(无论该接口上的子网配置和路由如何)。
您需要做的是尝试使用您想要检查的源地址进行 ping 操作(例如,而不是ping -I eth0 10.241.74.7
尝试ping -I 10.241.78.5 10.241.74.7
)。
这样,数据包将通过源地址离开,但是从实际配置了子网的10.241.78.5
正确接口离开。10.241.78.0/23