Can I assign a new IP address to an existing container?

Hi,

If you are using the default profile with the default network (I suppose its name is lxdbr0) you can modify the IP/mask with:

$ lxc network edit lxdbr0
config:
  ipv4.address: 10.0.0.254/24  <--- ip interface lxdbr0
  ipv4.dhcp.ranges: 10.0.0.100-10.0.0.150  <--- IP range to serve via dhcp
  ipv4.nat: "true"  <--- to create iptables SNAT rule
  ipv6.address: none
  ipv6.dhcp: "false"
  ipv6.nat: "false"
description: ""
name: lxdbr0
type: bridge
used_by: []
managed: true

It’s an example. You can see more options at https://github.com/lxc/lxd/blob/master/doc/networks.md
By default, your container will receive an IP config via dhcp; nevertheless, you can configure a static IP editing /etc/network/interfaces inside the container.

If you want your container has an IP from the real LAN, you have to use bridge mode or macvlan mode. See Another 'networking issue' or 'how to connect containers to more than one network using a bridge or macvlan'

1 Like