Hi,
I’ve tried to use routed interface like discussed here 3.19 and Routed networking mode configuration example needed - #11 by MSTY.
Here new test server with default configuration and I use only three commands:
- lxc profile copy default rnic
- lxc profile device remove rnic eth0
- lxc init ubuntu:18.04 c1 -p rnic
- lxc profile device add rnic eth0 nic nictype=routed parent=ens3
- lxc config device override c1 eth0 ipv4.address=7.0.0.1
- lxc start c1
This creates a container with configuration:
ubuntu@ubuntu-h2-2:~$ lxc config device show c1
eth0:
ipv4.address: 7.0.7.1
nictype: routed
parent: ens3
type: nic
ubuntu@ubuntu-h2-2:~$ lxc profile show rnic
config: {}
description: Default LXD profile
devices:
eth0:
nictype: routed
parent: ens3
type: nic
root:
path: /
pool: default
type: disk
name: rnic
used_by:
- /1.0/instances/c1
ubuntu@ubuntu-h2-2:~$
Container after start has ip for about 3-5 seconds but then it vanishes:
ubuntu@ubuntu-h2-2:~$ lxc list && lxc start c1 && lxc list && lxc exec c1 ip addr && lxc exec c1 ip route && lxc list && sleep 3 && lxc list && lxc exec c1 ip addr
+------+---------+------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+------+------+-----------+-----------+
| c1 | STOPPED | | | CONTAINER | 0 |
+------+---------+------+------+-----------+-----------+
+------+---------+----------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+----------------+------+-----------+-----------+
| c1 | RUNNING | 7.0.7.1 (eth0) | | CONTAINER | 0 |
+------+---------+----------------+------+-----------+-----------+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
23: eth0@if24: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:16:3e:38:36:65 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 7.0.7.1/32 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::216:3eff:fe38:3665/64 scope link tentative
valid_lft forever preferred_lft forever
default via 169.254.0.1 dev eth0
169.254.0.1 dev eth0 scope link
+------+---------+----------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+----------------+------+-----------+-----------+
| c1 | RUNNING | 7.0.7.1 (eth0) | | CONTAINER | 0 |
+------+---------+----------------+------+-----------+-----------+
+------+---------+------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+------+------+-----------+-----------+
| c1 | RUNNING | | | CONTAINER | 0 |
+------+---------+------+------+-----------+-----------+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
23: eth0@if24: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:16:3e:38:36:65 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::216:3eff:fe38:3665/64 scope link
valid_lft forever preferred_lft forever
ubuntu@ubuntu-h2-2:~$