Vanishing of IP address when using routed nic

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:

  1. lxc profile copy default rnic
  2. lxc profile device remove rnic eth0
  3. lxc init ubuntu:18.04 c1 -p rnic
  4. lxc profile device add rnic eth0 nic nictype=routed parent=ens3
  5. lxc config device override c1 eth0 ipv4.address=7.0.0.1
  6. 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:~$ 

Try removing /etc/netplan/10-lxc.yaml and restarting, it might be network configuration inside the container wiping out the IP configured by LXD.

Thanks, strange but it’s working. :grinning:
Removing /etc/netplan/50-cloud-init.yaml helped

1 Like

Its not so strange. That yaml file instructs netplan to start a DHCP client on the NIC, and in doing so the first thing the DHCP client does is remove any existing IPs from the NIC.

This is because for the majority of NIC types LXD expects there to be a DHCP service by default.
The routed NIC type is unusual in that it doesn’t support DHCP.

May I ask a little more
Is using 169.254.0.1/32 IP is mandatory on every interface and this is unchangeable?
This config uses true L3 routing, so no proxy ARP is used at all?

The use of the link local default gateways is required, but is only used to as the next-hop to get to the LXD host, once the packet has arrived there then the host’s routing table takes over.

1 Like