Ubuntu Server 中的静态路由无法正常工作

Ubuntu Server 中的静态路由无法正常工作

因此,我正在使用 Vagrant 和 Ubuntu 14.04 盒子创建一个虚拟计算机网络,基于此处显示的拓扑图片 1

这是我的 Vagrantfile。

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
    config.vm.box = "ubuntu/trusty32"
    config.vm.box_check_update = false
    config.vm.synced_folder '.', '/vagrant', disabled: true

    config.vm.provider "virtualbox" do |vb|
        vb.memory = "256"
    end

    config.vm.define "Router-1" do |r1|
        r1.vm.hostname = 'Router-1'

        r1.vm.network "private_network", ip: "192.168.10.1", netmask: "255.255.255.0", virtualbox__intnet: "c1r1net"
        r1.vm.network "private_network", ip: "192.168.1.1", netmask: "255.255.255.0", virtualbox__intnet: "r1r2net"
        r1.vm.network "private_network", ip: "192.168.2.1", netmask: "255.255.255.0", virtualbox__intnet: "r1r3net"

        r1.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--name", "Router-1"]
        end

        r1.vm.provision "shell", run: "always", inline: <<-SHELL
            sysctl -w net.ipv4.ip_forward=1
            route add -net 192.168.3.0/24 gw 192.168.1.2 dev eth2
            route add -net 192.168.20.0/24 gw 192.168.1.2 dev eth2
        SHELL
    end

    config.vm.define "Router-2" do |r2|
        r2.vm.hostname = 'Router-2'

        r2.vm.network "private_network", ip: "192.168.20.1", netmask: "255.255.255.0", virtualbox__intnet: "c2r2net"
        r2.vm.network "private_network", ip: "192.168.1.2", netmask: "255.255.255.0", virtualbox__intnet: "r1r2net"
        r2.vm.network "private_network", ip: "192.168.3.2", netmask: "255.255.255.0", virtualbox__intnet: "r2r3net"

        r2.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--name", "Router-2"]
        end

        r2.vm.provision "shell", run: "always", inline: <<-SHELL
            sysctl -w net.ipv4.ip_forward=1
            route add -net 192.168.2.0/24 gw 192.168.1.1 dev eth2
            route add -net 192.168.10.0/24 gw 192.168.1.1 dev eth2
        SHELL
    end

    config.vm.define "Router-3" do |r3|
        r3.vm.hostname = 'Router-3'

        r3.vm.network "private_network", ip: "192.168.2.3", netmask: "255.255.255.0", virtualbox__intnet: "r1r3net"
        r3.vm.network "private_network", ip: "192.168.3.3", netmask: "255.255.255.0", virtualbox__intnet: "r2r3net"

        r3.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--name", "Router-3"]
        end

        r3.vm.provision "shell", run: "always", inline: <<-SHELL
            sysctl -w net.ipv4.ip_forward=1
            route add -net 192.168.1.0/24 gw 192.168.2.1 dev eth1
            route add -net 192.168.10.0/24 gw 192.168.2.1 dev eth1
            route add -net 192.168.20.0/24 gw 192.168.3.2 dev eth2
        SHELL
    end

    config.vm.define "Client-1" do |c1|
        c1.vm.hostname = 'Client-1'

        c1.vm.network "private_network", ip: "192.168.10.2", netmask: "255.255.255.0", virtualbox__intnet: "c1r1net"

        c1.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--name", "Client-1"]
        end

        c1.vm.provision "shell", run: "always", inline: <<-SHELL
            route add default gw 192.168.10.1 eth1
        SHELL
    end

    config.vm.define "Client-2" do |c2|
        c2.vm.hostname = 'Client-2'

        c2.vm.network "private_network", ip: "192.168.20.2", netmask: "255.255.255.0", virtualbox__intnet: "c2r2net"

        c2.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--name", "Client-2"]
        end

        c2.vm.provision "shell", run: "always", inline: <<-SHELL
            route add default gw 192.168.20.1 eth1
        SHELL
    end
end

大部分情况下,一切都很好。问题发生在我尝试从Client-1向发送 ping 消息192.168.3.3,以及从Client-2向 发送192.168.2.3ping 消息,反之亦然时。ping 消息没有给出成功回复。

我是否遗漏了什么?

相关内容