【问题标题】:Multicasting with `socat` in Vagrant & VirtualBox Env在 Vagrant 和 VirtualBox 环境中使用“socat”进行多播
【发布时间】:2015-02-02 03:15:13
【问题描述】:

问题:同一网络中的每台机器都应该能够向所有成员广播,包括它自己。

这是尝试使用在 Vagrant 和 VirtualBox 环境中创建的 VM 使用 socat 进行多播工作。似乎这里的工作方式有所不同,所以我首先尝试看看多播如何在物理机器上工作。

我有 3 台物理机,上面安装了 ubuntu 12.04 服务器并命名为 pc0pc1pc2

在我运行的每台机器上: socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200

...当我从pc0 输入hi from pc0 时,它已经向自己和其他两台机器广播,这就是我想要的(我希望这就是多播应该如何工作):

ubuntu@pc0:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hi from pc0
hi from pc0

ubuntu@pc1:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hi from pc0

ubuntu@pc2:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hi from pc0

我正在使用 IP 224.0.0.1,因为它默认用于每台机器上的多播。

接下来,我尝试用 3 个 VM 实现相同的东西,vb0vb1vb2。 Github repo 是here

现在我尝试从vb0进行广播:

vagrant@vb0:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hello from vb0
hello from vb0

...除了它自己之外,它不会向其他成员广播(如上面的物理机器)。

看来,在进行这项工作之前,还应该进行一些额外的设置...

Vagrantfile:

Vagrant.configure(2) do |config|

    config.vm.box = "ubuntu-12.04-x64"
    config.vm.synced_folder ".", "/vagrant", disabled: true

    config.vm.provider "virtualbox" do |vb|
        vb.cpus    = "2"
        vb.memory = "4096"
    end

    config.vm.provision "chef_apply" do |chef|
        chef.recipe = File.read("recipe.rb")
    end

    config.vm.define "vb0" do |vb0|
        vb0.vm.hostname = "vb0"
        vb0.vm.network "private_network", ip: "10.20.30.100"
    end

    config.vm.define "vb1" do |vb1|
        vb1.vm.hostname = "vb1"
        vb1.vm.network "private_network", ip: "10.20.30.101"
    end

    config.vm.define "vb2" do |vb2|
        vb2.vm.hostname = "vb2"
        vb2.vm.network "private_network", ip: "10.20.30.102"
    end

end

【问题讨论】:

    标签: udp vagrant virtualbox multicast socat


    【解决方案1】:

    在每个设备上运行(即vb01vb1vb2):

    sudo ip route add 224.0.0.0/4 dev eth1

    解决了这个问题。

    在物理环境中,它可以在不这样做的情况下工作。 不知道为什么我们必须在这样的虚拟环境中运行它。

    vagrant@vb0:~$ route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    default         10.0.2.2        0.0.0.0         UG    100    0        0 eth0
    10.0.2.0        *               255.255.255.0   U     0      0        0 eth0
    10.20.30.0      *               255.255.255.0   U     0      0        0 eth1
    224.0.0.0       *               240.0.0.0       U     0      0        0 eth1
    

    有用的参考http://troglobit.github.io/multicast-howto.html

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 2014-08-02
      • 2015-10-30
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      相关资源
      最近更新 更多