且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Virtualbox/Vagrant 中列出 natpf 规则

更新时间:2023-10-17 10:48:52

我也遇到了同样的问题;根据您关于删除规则的提示,我发现您可以使用 VirtualBox GUI 查找规则并删除它们.

I came here with the same problem; with your hint about deleting the rule I found that you can use the VirtualBox GUI to find the rules and delete them.

当然,这只适用于您在带有 GUI 桌面的机器上工作.

Of course, this only works when you are working on a machine with a GUI desktop.

  • 打开 VirtualBox 管理器
  • 打开相关框的设置(rmb -> 设置或齿轮图标)
  • 从左侧列表中选择Network并打开Port Forwarding对话框
  • Open the VirtualBox manager
  • Open the settings for the box in question (rmb -> settings, or the gear icon)
  • Select Network from the list on the left and open the Port Forwarding dialogue

从这里您可以直接删除规则.

From here you'll be able to directly remove the rules.

http://i.stack.imgur.com/6fQQc.png

查看规则,似乎他们只是获得了一个与正在设置的端口相同的名称.所以你也可以查看 Vagrantfile,并搜索这样的一行:

Looking at the rules, it seems they just get a name that is equal to the port being set. So you can also look at the Vagrantfile, and search for a line like this:

db.vm.network :forwarded_port, guest: 5432, host: 5432

并猜测规则的名称将是 5432.转发 ssh 端口 22 的规则名称,称为 ssh

And guess that the name of the rule will be 5432. The name of the rule for forwarding the ssh port 22, is called ssh

$ vboxmanage modifyvm "vbox-id" --natpf1 delete "5432"