gpt4 book ai didi

vagrant - 如何在 Vagrant 中自动选择桥接网络接口(interface)?

转载 作者:行者123 更新时间:2023-12-03 10:14:29 25 4
gpt4 key购买 nike

我应该在 Vagrant 文件中添加什么以防止询问(在 vagrant up 命令之后)

Which interface should the network bridge to?


Available bridged network interfaces:
1) Intel(R) 82579LM Gigabit Network Connection
2) VMware Virtual Ethernet Adapter for VMnet1
3) VMware Virtual Ethernet Adapter for VMnet8

我想选择#1 选项。
当前我需要手动输入“1”。
请帮忙!

最佳答案

对于 Linux,我使用该文件是 Ruby 脚本这一事实来检测默认路由并使用该接口(interface)的名称。这允许我们整个团队按原样使用 Vagrantfile,而无需硬编码接口(interface)名称或不断更新列表。我想你可以在 Windows 或 Mac 上做类似的事情(猜测 Mac 可能实际上是相同的,因为它是 *​​nix)。
请注意,如果未检测到默认网络接口(interface),系统仍会提示您选择一个。

# Grab the name of the default interface
$default_network_interface = `ip route | awk '/^default/ {printf "%s", $5; exit 0}'`
...
Vagrant.configure("2") do |config|
# Specify the interface when creating the public network
config.vm.network "public_network", bridge: "#$default_network_interface"
...
end

关于vagrant - 如何在 Vagrant 中自动选择桥接网络接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33250304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com