Container does not get static address on lxdbr0

networking

(Alexander) #1

Hello

I have default LXD bridge
$ lxc network list
±-------±---------±--------±------------±--------+
| NAME | TYPE | MANAGED | DESCRIPTION | USED BY |
±-------±---------±--------±------------±--------+
| enp4s0 | physical | NO | | 0 |
±-------±---------±--------±------------±--------+
| lxdbr0 | bridge | YES | | 2 |
±-------±---------±--------±------------±--------+

I create a brand new container c1
$ lxc launch ubuntu:18.04 c1

Container nicely runs with dhcp assigned address
$ lxc list c1
±---------------±--------±------------------±-----±-----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±---------------±--------±------------------±-----±-----------±----------+
| c1 | RUNNING | 10.0.0.198 (eth0) | | PERSISTENT | 0 |
±---------------±--------±------------------±-----±-----------±----------+

I attach network to container c1
$ lxc network attach lxdbr0 c1 eth0

I assign static IP address to container
$ lxc config device set c1 eth0 ipv4.address 10.0.0.5/24

I restart container c1
$ lxc restart c1

== and problem is that container does not get any IP address any more ==

$ lxc list c1
±-----±--------±-----±-----±-----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±-----±--------±-----±-----±-----------±----------+
| c1 | RUNNING | | | PERSISTENT | 0 |
±-----±--------±-----±-----±-----------±----------+

How to set static ip address on a container connected to LXD managed bridge?

Alex


(Johannes Midgren) #2

There are different methods to do it, but one simple way is like this:

  • Instead of “launching” the container directly you simply init it so that it’s created but not started
  • Attach the network to it
  • Configure the network device
  • Lastly, start it

Or in code:

$ lxc init ubuntu:18.04 c1
Creating c1
$ lxc network attach lxdbr0 c1 eth0
$ lxc config device set c1 eth0 ipv4.address 10.0.0.5
$ lxc start c1

At least for Ubuntu images you can also use cloud-init, but the syntax varies depending on underlying tools and will thus vary between operating systems and releases. It is on the other hand capable of configuring more than network settings.


(John Teague) #3

That’s good advice. You also get the basic config the way you want it, then create an image from it. You can take advantage of image cache from that for fast replication or cloning if that works better for you.


(Alexander) #4

Thanks for the answer Johannes

Finally I solved the problem by restarting the whole LXD Host. Then my container got proper static ip address.
No idea why is that.
I also tried your method it is interesting too.

Alex


(Alexander) #5

Johannes

Offtopic question: in your reply, how did you manage to get code formated w/ different font and background?


#6

He used markdown formatting. When you click to reply a post, you get some formatting icons such as B for bold, I for italics and so on. The one that has the icon </> is for preformatted text, and it’s the one used above.

You can also type these special formatting directly without using the icons. Read more at https://guides.github.com/features/mastering-markdown/


(Johannes Midgren) #7

I don’t know if it’s the same on mobile, but in my browser I get a basic editor when making posts or replying. By highlighting text and then clicking the icon looking like </> the text gets indented. Indentation is used in markdown as one means of making text appear without formatting in a monospaced font. There have to be blank lines before and after such a paragraph though.

You can also use backticks in numerous ways, see the link above!