对此图的Linux“路由添加”命令感到困惑

网络工程 路由 路由器 linux
2022-03-06 19:46:19

我对这个网络图感到困惑。

在课堂上,路由器 R1 分配给了我,其他学生在图表上获得了各种路由器/工作站。我们的任务是使用 ifconfig 和 route 命令设置网络。由于主路由器实际上只有一个物理接口,因此我们也使用了别名(eth0 和 eth0:1)。

我使用以下命令设置 R1(最初我的网关错误)但我的教授纠正了我:

# set interfaces (1 physical/1 virtual)
  ifconfig eth0 10.0.0.4/24
  ifconfig eth0:1 10.0.14.252/24

# Add routes for remaining 4 LANs:
  route add -net 10.0.12.0 netmask 255.255.255.0 gw 10.0.14.27
  route add -net 10.0.17.0 netmask 255.255.255.0  gw 10.0.14.34
  route add -net 10.0.7.0 netmask 255.255.255.0  gw 10.0.14.27
  route add -net 10.0.28.0 netmask 255.255.255.0  gw 10.0.14.34

# once everyone can ping eachother successfully
# connect the entire 10.0.0.0/24 network to the
# outside 192.168.104.0/22 network
  route add default gw 10.0.0.1

# set up forwarding to outside gateway
  sysctl -w net.ipv4.ip_forward=1

我最困惑为什么路由命令的 gw 是 10.0.14.34 和 10.0.14.27。

R3 或 R5 的路由命令和网关是什么?还是 R2 和 R4?我可以看到两个 ifconfig 命令添加了路由器的两个相邻网络;没有必要设置他们的路线。但是我真的很困惑每个路由器的每一端都用于网关。

很感谢任何形式的帮助!谢谢你。

1个回答

网关就像一扇通往其他子网的门。为了到达有问题的子网,您需要知道使用哪个门。

在 R3 上,您需要:

route add -net 10.0.0.0 netmask 255.255.255.0 gw 10.0.14.252
route add -net 10.0.12.0 netmask 255.255.255.0  gw 10.0.14.27
route add -net 10.0.7.0 netmask 255.255.255.0  gw 10.0.14.27
route add -net 10.0.28.0 netmask 255.255.255.0  gw 10.0.17.28

在 R5 上,您可以使用 R3 作为默认网关,因为所有非本地子网都在它后面:

route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.0.17.24