MAC address can be specified on all network interfaces.

This commit is contained in:
Jevgeni Kiski
2013-09-17 00:23:24 +03:00
parent 1e2f49f028
commit 3bcf9496de
4 changed files with 14 additions and 6 deletions

View File

@@ -167,12 +167,12 @@ An examples of network interface definitions:
```ruby
# Private network
config.vm.define :test_vm1 do |test_vm1|
test_vm1.vm.network :private_network, :ip => "10.20.30.40",
test_vm1.vm.network :private_network, :ip => "10.20.30.40"
end
# Public Network
config.vm.define :test_vm1 do |test_vm1|
test_vm1.vm.network :public_network, :dev => "eth0", :mode => 'bridge', :mac => '92-c6-8f-94-b5-8d'
test_vm1.vm.network :public_network, :dev => "eth0", :mode => 'bridge'
end
```
@@ -191,7 +191,7 @@ The second interface is created and bridged into the physical device 'eth0'.
This mechanism uses the macvtap Kernel driver and therefore does not require
an existing bridge device. This configuration assumes that DHCP and DNS services
are being provided by the public network. This public interface should be reachable
by anyone with access to the public network. If `:mac` is not defined it will be generated.
by anyone with access to the public network.
### Private Network Options
@@ -217,12 +217,14 @@ starts with 'libvirt__' string. Here is a list of those options:
* `:libvirt__forward_device` - Name of interface/device, where network should
be forwarded (NATed or routed). Used only when creating new network. By
default, all physical interfaces are used.
* `:mac` - MAC address for the interface.
### Public Network Options
* `:dev` - Physical device that the public interface should use. Default is 'eth0'
* `:mode` - The mode in which the public interface should operate in. Supported
modes are available from the [libvirt documentation](http://www.libvirt.org/formatdomain.html#elementsNICSDirect).
Default mode is 'bridge'.
* `:mac` - MAC address for the interface.
## Obtaining Domain IP Address

View File

@@ -65,6 +65,7 @@ module VagrantPlugins
adapters.each_with_index do |iface_configuration, slot_number|
@iface_number = slot_number
@network_name = iface_configuration[:network_name]
@mac = iface_configuration.fetch(:mac, false)
template_name = 'interface'
# Configuration for public interfaces which use the macvtap driver
@@ -72,12 +73,14 @@ module VagrantPlugins
template_name = 'public_interface'
@device = iface_configuration.fetch(:dev, 'eth0')
@mode = iface_configuration.fetch(:mode, 'bridge')
@mac = iface_configuration.fetch(:mac, false)
@logger.info("Setting up public interface using device #{@device} in mode #{@mode}")
end
message = "Creating network interface eth#{@iface_number}"
message << " connected to network #{@network_name}."
if @mac
message << "Using MAC address: #{@mac}"
end
@logger.info(message)
begin

View File

@@ -1,8 +1,8 @@
<interface type='network'>
<source network='<%= @network_name %>'/>
<% if @mac %>
<% if @mac %>
<mac address='<%= @mac %>'/>
<% end %>
<% end %>
<target dev='vnet<%= @iface_number %>'/>
<alias name='net<%= @iface_number %>'/>
<model type='virtio'/>

View File

@@ -1,4 +1,7 @@
<interface type='direct'>
<% if @mac %>
<mac address='<%= @mac %>'/>
<% end %>
<source dev='<%= @device %>' mode='<%= @mode %>'/>
</interface>