Skip to content

Use nmstatectl apply --kernel to implement use_static_ip=true

Alexander Larsson requested to merge nmstateapply into main

This makes static ip get loaded really early, and doesn't rely on NetworkManager.

To test this you can e.g. build sample-images like:

AIB=/your/checkout/of/automotive-image-builder/automotive-image-builder ./build cs9-qemu-minimal-regular.x86_64.qcow2 --define use_static_ip=true --define 'extra_rpms=["iputils","iproute"]'

This will use an /etc/main.nmstate like this:

---
interfaces:
  - name: eth0
    type: ethernet
    state: up
    ipv4:
      enabled: true
      dhcp: false
      address:
        - ip: 10.0.2.15
          prefix-length: 24
    ipv6:
      enabled: false
routes:
  config:
    - destination: 0.0.0.0/0
      next-hop-interface: eth0
      next-hop-address: 10.0.2.2
dns-resolver:
  config:
    server:
      - 10.0.2.3

Which is loaded very early (before systemd-udevd.service) by the main-nmstate.service unit to bring up the network.

This seems to work to some degree:

# ip addr
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
2: enp0s2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether fe:16:51:94:f5:a1 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global enp0s2
       valid_lft forever preferred_lft forever
    inet6 fec0::fc16:51ff:fe94:f5a1/64 scope site dynamic mngtmpaddr 
       valid_lft 86310sec preferred_lft 14310sec
    inet6 fe80::fc16:51ff:fe94:f5a1/64 scope link 
       valid_lft forever preferred_lft forever
# ip route
10.0.2.0/24 dev enp0s2 proto kernel scope link src 10.0.2.15 
# ping 10.0.2.2
PING 10.0.2.2 (10.0.2.2) 56(84) bytes of data.
64 bytes from 10.0.2.2: icmp_seq=1 ttl=255 time=0.061 ms

However, it doesn't seem to apply the default route or the dns config:

# ping 8.8.8.8
ping: connect: Network is unreachable
# ping redhat.com
ping: redhat.com: Name or service not known

Merge request reports

Loading