Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Static IP #296

Closed
PierrePaul opened this issue Jun 4, 2014 · 8 comments
Closed

Static IP #296

PierrePaul opened this issue Jun 4, 2014 · 8 comments

Comments

@PierrePaul
Copy link

Im using the 1.0.0.alpha.2, under Ubuntu 14.04 as the Host.
I'm trying to spawn guest running ubuntu 14.04 (trusty).
My LXC version:
Architecture: amd64
Version: 1.0.3-0ubuntu3

I'm trying to bind a static IP on the container using :
lxc.customize 'network.ipv4', 10.0.3.102

The IP is withing the DHCP range of my dnsmasq.
The container starts with a DHCP IP (10.0.3.180, or any IP under 10.0.3.*).
If I do a vagrant reload though, it resets the IP correctly to 10.0.3.102.

I have not found a good way to redirect the output correctly to a log file, so here is the revelant part(at least I think it is revelant) of the vagrant up --provider=lxc :

 INFO subprocess: Starting process: ["/usr/bin/sudo", "lxc-info", "--name", "lvh_db_1401908345415_22708"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: Name:           lvh_db_1401908345415_22708
State:          RUNNING
PID:            5673
DEBUG subprocess: stdout: IP:             10.0.3.102
CPU use:        0.57 seconds
BlkIO use:      76.00 KiB
Memory use:     7.51 MiB
KMem use:       0 bytes
Link:           veth2D70RD
 TX bytes:      690 bytes
 RX bytes:      432 bytes
 Total bytes:   1.10 KiB
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
 INFO machine: Calling action: fetch_ip on provider LXC (lvh_db_1401908345415_22708)
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 1 hooks defined.
 INFO runner: Running action: #<Vagrant::Action::Builder:0x007f9c68469f18>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::ConfigValidate:0x007f9c6847f660>
 INFO warden: Calling IN action: #<Vagrant::LXC::Action::FetchIpWithLxcAttach:0x007f9c6847f638>
 INFO subprocess: Starting process: ["/usr/bin/sudo", "lxc-attach", "--name", "lvh_db_1401908345415_22708", "--namespaces", "NETWORK", "--", "/sbin/ip", "-4", "addr", "show", "scope", "global", "eth0"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
 INFO retryable: Retryable exception raised: #<Vagrant::LXC::Errors::ExecuteError: There was an error executing lxc-attach

For more information on the failure, enable detailed logging by setting
the environment variable VAGRANT_LOG to DEBUG.>
 INFO subprocess: Starting process: ["/usr/bin/sudo", "lxc-attach", "--name", "lvh_db_1401908345415_22708", "--namespaces", "NETWORK", "--", "/sbin/ip", "-4", "addr", "show", "scope", "global", "eth0"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: 43: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 10.0.3.247/24 brd 10.0.3.255 scope global eth0
       valid_lft forever preferred_lft forever
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0
 INFO warden: Calling IN action: #<Vagrant::LXC::Action::FetchIpFromDnsmasqLeases:0x000000023aa708>
 INFO warden: Calling OUT action: #<Vagrant::LXC::Action::FetchIpFromDnsmasqLeases:0x000000023aa708>
 INFO warden: Calling OUT action: #<Vagrant::LXC::Action::FetchIpWithLxcAttach:0x007f9c6847f638>
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::ConfigValidate:0x007f9c6847f660>

In the LXC config file for the container I have the correct IP (10.0.3.102) and I am suspecting that reload will force a read on the config file and put the right IP, while a vagrant up might try to do some unwanted magic after booting the container with a valid IP.

Any ideas what I should look at?

@fgrehm
Copy link
Owner

fgrehm commented Jun 5, 2014

The plugin should write to the config file before bringing up the container for the first time. Unfortunately I dunno what might be causing that. I'll try to give it a go when I have a chance but if you have new information to share please let us know!

@PierrePaul
Copy link
Author

The config is written before starting up. The machine is also starting with the good IP. I'm trying to find out why for no apparent reason the machine is changing IP.

@fgrehm
Copy link
Owner

fgrehm commented Jun 6, 2014

@PierrePaul would you be able to try to reproduce this with plain old lxc without vagrant-lxc just to make sure this is something related to the plugin and not with lxc itself? if you need help with that please lmk

@PierrePaul
Copy link
Author

Plain lxc works, with the same rootfs and a copied config. IP is not overwritten.

@PierrePaul
Copy link
Author

I just noticed I havent put my Vagrantfile Config :

VAGRANTFILE_API_VERSION = '2'
VAGRANT_DEFAULT_PROVIDER = 'lxc'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = 'lxc-trusty64-04072014'
  config.vm.provider :lxc do |lxc, override|
    lxc.customize 'network.ipv4', '10.0.3.125/24'
  end
end

Also, while debugging, I found out that Dnsmasq actually gives it an IP. Even though one is already set here.

@PierrePaul
Copy link
Author

For those finding this thread via the search or Google, this is no longer enough to have a static IP for vagrant-lxc :

lxc.customize 'network.ipv4', '10.0.3.125/24'

Getting a static IP is part of the big task #298
There is a way though to get the fixed IP working non-officialy, according to #120 (thanks to @cbanbury)

lxc.customize "network.type", "veth"
lxc.customize "network.link", "lxcbr1"
lxc.customize "network.ipv4", "10.0.3.x/24"

Under ubuntu 14.04 with the default settings, the link should be called lxcbr0 giving the following config :

lxc.customize "network.type", "veth"
lxc.customize "network.link", "lxcbr0"
lxc.customize "network.ipv4", "10.0.3.x/24"

@PierrePaul
Copy link
Author

Another thing, in my case my base box (from the official repo https://github.com/fgrehm/vagrant-lxc-base-boxes ) was using eth0 on dhcp. vagrant-lxc was setting the IP on eth0 (instead of creating a new virtual interface), then the dhcp would kick in and re-assign a new IP over the eth0. Moving the basebox eth0 to eth1 made it all work for me.

@fgrehm
Copy link
Owner

fgrehm commented Jul 4, 2014

Thanks for the info. It's sad to know that lxc.customize 'network.ipv4', '10.0.3.125/24' is no longer enough :-(

I'll try to get to implement a proper support for private networks this month.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants