auto_nat_dns_proxy VirtualBox provider config option [GH-1313]
When set to false, Vagrant will no longer try to automatically manage NAT DNS proxy settings with VirtualBox.
This commit is contained in:
parent
25713e4568
commit
f713082280
|
@ -30,6 +30,9 @@ FEATURES:
|
||||||
This decreases Vagrant's initial startup time considerably.
|
This decreases Vagrant's initial startup time considerably.
|
||||||
- Allow "file://" URLs for box URLs. [GH-1087]
|
- Allow "file://" URLs for box URLs. [GH-1087]
|
||||||
- Emit "vagrant-mount" upstart event when NFS shares are mounted. [GH-1118]
|
- Emit "vagrant-mount" upstart event when NFS shares are mounted. [GH-1118]
|
||||||
|
- Add a VirtualBox provider config `auto_nat_dns_proxy` which when set to
|
||||||
|
false will not attempt to automatically manage NAT DNS proxy settings
|
||||||
|
with VirtualBox. [GH-1313]
|
||||||
|
|
||||||
IMPROVEMENTS / BUG FIXES:
|
IMPROVEMENTS / BUG FIXES:
|
||||||
|
|
||||||
|
|
|
@ -25,34 +25,21 @@ module VagrantPlugins
|
||||||
]
|
]
|
||||||
attempt_and_log(command, "Enabling the Host I/O cache on the SATA controller...")
|
attempt_and_log(command, "Enabling the Host I/O cache on the SATA controller...")
|
||||||
|
|
||||||
enable_dns_proxy = true
|
if env[:machine].provider_config.auto_nat_dns_proxy
|
||||||
begin
|
@logger.info("Automatically figuring out whether to enable/disable NAT DNS proxy...")
|
||||||
contents = File.read("/etc/resolv.conf")
|
|
||||||
|
|
||||||
if contents =~ /^nameserver 127\.0\.(0|1)\.1$/
|
# Enable/disable the NAT DNS proxy as necessary
|
||||||
# The use of both natdnsproxy and natdnshostresolver break on
|
if enable_dns_proxy?
|
||||||
# Ubuntu 12.04 and 12.10 that uses resolvconf with localhost. When used
|
command = ["modifyvm", env[:machine].id, "--natdnsproxy1", "on"]
|
||||||
# VirtualBox will give the client dns server 10.0.2.3, while
|
attempt_and_log(command, "Enable the NAT DNS proxy on adapter 1...")
|
||||||
# not binding to that address itself. Therefore disable this
|
else
|
||||||
# feature if host uses the resolvconf server 127.0.0.1 or
|
command = [ "modifyvm", env[:machine].id, "--natdnsproxy1", "off" ]
|
||||||
# 127.0.1.1
|
attempt_and_log(command, "Disable the NAT DNS proxy on adapter 1...")
|
||||||
@logger.info("Disabling DNS proxy since resolv.conf contains 127.0.0.1 or 127.0.1.1")
|
command = [ "modifyvm", env[:machine].id, "--natdnshostresolver1", "off" ]
|
||||||
enable_dns_proxy = false
|
attempt_and_log(command, "Disable the NAT DNS resolver on adapter 1...")
|
||||||
end
|
end
|
||||||
rescue Errno::ENOENT; end
|
|
||||||
|
|
||||||
# Enable/disable the NAT DNS proxy as necessary
|
|
||||||
if enable_dns_proxy
|
|
||||||
command = [
|
|
||||||
"modifyvm", env[:machine].id,
|
|
||||||
"--natdnsproxy1", "on"
|
|
||||||
]
|
|
||||||
attempt_and_log(command, "Enable the NAT DNS proxy on adapter 1...")
|
|
||||||
else
|
else
|
||||||
command = [ "modifyvm", env[:machine].id, "--natdnsproxy1", "off" ]
|
@logger.info("NOT trying to automatically manage NAT DNS proxy.")
|
||||||
attempt_and_log(command, "Disable the NAT DNS proxy on adapter 1...")
|
|
||||||
command = [ "modifyvm", env[:machine].id, "--natdnshostresolver1", "off" ]
|
|
||||||
attempt_and_log(command, "Disable the NAT DNS resolver on adapter 1...")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
@ -70,6 +57,30 @@ module VagrantPlugins
|
||||||
result = @env[:machine].provider.driver.execute_command(command)
|
result = @env[:machine].provider.driver.execute_command(command)
|
||||||
@logger.info("#{log} (exit status = #{result.exit_code})")
|
@logger.info("#{log} (exit status = #{result.exit_code})")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This uses some heuristics to determine if the NAT DNS proxy should
|
||||||
|
# be enabled or disabled. See the comments within the function body
|
||||||
|
# itself to see the checks it does.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
def enable_dns_proxy?
|
||||||
|
begin
|
||||||
|
contents = File.read("/etc/resolv.conf")
|
||||||
|
|
||||||
|
if contents =~ /^nameserver 127\.0\.(0|1)\.1$/
|
||||||
|
# The use of both natdnsproxy and natdnshostresolver break on
|
||||||
|
# Ubuntu 12.04 and 12.10 that uses resolvconf with localhost. When used
|
||||||
|
# VirtualBox will give the client dns server 10.0.2.3, while
|
||||||
|
# not binding to that address itself. Therefore disable this
|
||||||
|
# feature if host uses the resolvconf server 127.0.0.1 or
|
||||||
|
# 127.0.1.1
|
||||||
|
@logger.info("Disabling DNS proxy since resolv.conf contains 127.0.0.1 or 127.0.1.1")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
rescue Errno::ENOENT; end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module ProviderVirtualBox
|
module ProviderVirtualBox
|
||||||
class Config < Vagrant.plugin("2", :config)
|
class Config < Vagrant.plugin("2", :config)
|
||||||
|
# Vagrant by default will make "smart" decisions to enable/disable
|
||||||
|
# the NAT DNS proxy. If this is set to `true`, then the DNS proxy
|
||||||
|
# will not be enabled, and it is up to the end user to do it.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
attr_accessor :auto_nat_dns_proxy
|
||||||
|
|
||||||
# An array of customizations to make on the VM prior to booting it.
|
# An array of customizations to make on the VM prior to booting it.
|
||||||
#
|
#
|
||||||
# @return [Array]
|
# @return [Array]
|
||||||
|
@ -17,6 +24,7 @@ module VagrantPlugins
|
||||||
attr_reader :network_adapters
|
attr_reader :network_adapters
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
@auto_nat_dns_proxy = UNSET_VALUE
|
||||||
@customizations = []
|
@customizations = []
|
||||||
@network_adapters = {}
|
@network_adapters = {}
|
||||||
@gui = UNSET_VALUE
|
@gui = UNSET_VALUE
|
||||||
|
@ -53,6 +61,9 @@ module VagrantPlugins
|
||||||
# This is the hook that is called to finalize the object before it
|
# This is the hook that is called to finalize the object before it
|
||||||
# is put into use.
|
# is put into use.
|
||||||
def finalize!
|
def finalize!
|
||||||
|
# Default is to auto the DNS proxy
|
||||||
|
@auto_nat_dns_proxy = true if @auto_nat_dns_proxy == UNSET_VALUE
|
||||||
|
|
||||||
# Default is to not show a GUI
|
# Default is to not show a GUI
|
||||||
@gui = false if @gui == UNSET_VALUE
|
@gui = false if @gui == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue