network configuration fails on CentoS 7.5: using dhcp instead of static address

Bug #1771116 reported by Martin Steigerwald
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Invalid
Undecided
Unassigned
cloud-init (CentOS)
Confirmed
Undecided

Bug Description

Cloud-Provider: NoCloud via Proxmox and qm set

I have centostemplate CentOS 7.5 VM on Proxmox and with:

[root@centostemplate ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=9c[…]
DEVICE=eth0
ONBOOT=yes
DNS1=10.0.0.4
DOMAIN=qs.de
IPADDR=10.0.88.101
PREFIX=8
GATEWAY=10.0.0.4
IPV6_PRIVACY=no
PROXY_METHOD=none
BROWSER_ONLY=no

I have a script that on Proxmox does:

- qm clone 2100 2101 --name centos1
- qm set 2101 --ipconfig0 ip=10.0.88.151/8,gw=10.0.0.4 --cores 2 --memory 4096
- qm start 2101

I get

[root@centos1 ~]# cat /mnt/zeit/network-config
version: 1
config:
    - type: physical
      name: eth0
      mac_address: F2:15:C8:E1:0A:49
      subnets:
      - type: static
        address: 10.0.88.151/8
        gateway: 10.0.0.4
    - type: nameserver
      address:
      - 10.0.0.4
      search:
      - somedomain.de

[root@centos1 ~]# ip -4 addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 10.0.0.161/16 brd 10.0.255.255 scope global noprefixroute dynamic eth0
       valid_lft 171536sec preferred_lft 171536sec

and:

[root@centos1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=10.0.0.4
HWADDR=F2:15:C8:E1:0A:49
IPADDR=10.0.88.151/8
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
[root@centos1 ~]# ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether f2:15:c8:e1:0a:49 brd ff:ff:ff:ff:ff:ff

Yet while this works it is wrong on RedHat. It has to be:

IPADDR=10.0.88.151
PREFIX=8

Otherwise I get this:

[root@centos1 ~]# LANG=C ifup eth0
ipcalc: both netmask and prefix specified
Usage: ipcalc [OPTION...]
  -c, --check Validate IP address for specified address family
  -4, --ipv4 IPv4 address family (default)
  -6, --ipv6 IPv6 address family
  -b, --broadcast Display calculated broadcast address
  -h, --hostname Show hostname determined via DNS
  -m, --netmask Display default netmask for IP (class A, B, or C)
  -n, --network Display network address
  -p, --prefix Display network prefix
  -s, --silent Don't ever display error messages

Help options:
  -?, --help Show this help message
  --usage Display brief usage message
ipcalc: both netmask and prefix specified
Usage: ipcalc [OPTION...]
  -c, --check Validate IP address for specified address family
  -4, --ipv4 IPv4 address family (default)
  -6, --ipv6 IPv6 address family
  -b, --broadcast Display calculated broadcast address
  -h, --hostname Show hostname determined via DNS
  -m, --netmask Display default netmask for IP (class A, B, or C)
  -n, --network Display network address
  -p, --prefix Display network prefix
  -s, --silent Don't ever display error messages

Help options:
  -?, --help Show this help message
  --usage Display brief usage message
ipcalc: both netmask and prefix specified
Usage: ipcalc [OPTION...]
  -c, --check Validate IP address for specified address family
  -4, --ipv4 IPv4 address family (default)
  -6, --ipv6 IPv6 address family
  -b, --broadcast Display calculated broadcast address
  -h, --hostname Show hostname determined via DNS
  -m, --netmask Display default netmask for IP (class A, B, or C)
  -n, --network Display network address
  -p, --prefix Display network prefix
  -s, --silent Don't ever display error messages

Help options:
  -?, --help Show this help message
  --usage Display brief usage message
arping: 10.0.88.151/8: Name or service not known
Error: any valid prefix is expected rather than "10.0.88.151/8/".
ERROR : [/etc/sysconfig/network-scripts/ifup-eth] Error adding address 10.0.88.151/8 for eth0.
arping: 10.0.88.151/8: Name or service not known
Error: any valid prefix is expected rather than "10.0.88.151/8/".
RTNETLINK answers: File exists

Consequently this little change fixes the issue:

[root@centos1 ~]# diff -u /etc/sysconfig/network-scripts/ifcfg-eth0.cloud-init.orig /etc/sysconfig/network-scripts/ifcfg-eth0
--- /etc/sysconfig/network-scripts/ifcfg-eth0.cloud-init.orig 2018-05-14 14:29:42.801000000 +0200
+++ /etc/sysconfig/network-scripts/ifcfg-eth0 2018-05-14 14:59:48.352000000 +0200
@@ -5,7 +5,8 @@
 DEVICE=eth0
 GATEWAY=10.0.0.4
 HWADDR=F2:15:C8:E1:0A:49
-IPADDR=10.0.88.151/8
+IPADDR=10.0.88.151
+PREFIX=8
 ONBOOT=yes
 TYPE=Ethernet
 USERCTL=no

Revision history for this message
In , Martin (martin-redhat-bugs) wrote :
Download full text (4.1 KiB)

Using CentOS but reporting here as the fix needs to go into the upstream source and then RHEL RPM anyway before going into CentOS, also reported there, see under "Additional info".

Description of problem:

cloud-init configures static network wrongly as:

IPADDR=10.0.88.151/8

instead of

IPADDR=10.0.88.151
PREFIX=8

Version-Release number of selected component (if applicable):

cloud-init-0.7.9-24.el7.centos.x86_64

How reproducible:

Always.

Steps to Reproduce:
1. Have a network configuration like (here via NoCloud source on Proxmox):

[root@centos1 ~]# mount | grep sr0
/dev/sr0 on /mnt/zeit type iso9660 (ro,relatime)
[root@centos1 ~]# cat /mnt/zeit/
meta-data network-config user-data
[root@centos1 ~]# cat /mnt/zeit/network-config
version: 1
config:
    - type: physical
      name: eth0
      mac_address: F2:15:C8:E1:0A:49
      subnets:
      - type: static
        address: 10.0.88.151/8
        gateway: 10.0.0.4
    - type: nameserver
      address:
      - 10.0.0.4
      search:
      - somedomain.de

2. Boot the image with this cloud init configuration

Actual results:

[root@centos1 network-scripts]# cat ifcfg-eth0.cloud-init.orig
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=10.0.0.4
HWADDR=F2:15:C8:E1:0A:49
IPADDR=10.0.88.151/8
ONBOOT=yes
TYPE=Ethernet
USERCTL=no

Which leads to:

[root@centos1 ~]# LANG=C ifup eth0
ipcalc: both netmask and prefix specified
Usage: ipcalc [OPTION...]
  -c, --check Validate IP address for specified address family
  -4, --ipv4 IPv4 address family (default)
  -6, --ipv6 IPv6 address family
  -b, --broadcast Display calculated broadcast address
  -h, --hostname Show hostname determined via DNS
  -m, --netmask Display default netmask for IP (class A, B, or C)
  -n, --network Display network address
  -p, --prefix Display network prefix
  -s, --silent Don't ever display error messages

Help options:
  -?, --help Show this help message
  --usage Display brief usage message
ipcalc: both netmask and prefix specified
Usage: ipcalc [OPTION...]
  -c, --check Validate IP address for specified address family
  -4, --ipv4 IPv4 address family (default)
  -6, --ipv6 IPv6 address family
  -b, --broadcast Display calculated broadcast address
  -h, --hostname Show hostname determined via DNS
  -m, --netmask Display default netmask for IP (class A, B, or C)
  -n, --network Display network address
  -p, --prefix Display network prefix
  -s, --silent Don't ever display error messages

Help options:
  -?, --help Show this help message
  --usage Display brief usage message
ipcalc: both netmask and prefix specified
Usage: ipcalc [OPTION...]
  -c, --check Validate IP address for specified address family
  -4, --ipv4 IPv4 address family (default)
  -6, --ipv6 IPv6 address family
  -b, --broadcast Display calculated broadcast address
  -h, --hostname Show hostname determined via DNS
  -m, --netmask Display default netmask for IP (class A, B, or C)
  -n, --network Display network address
  -p, --prefix Display network prefix
  -s, --silent Don't ever display error messages

Help options:
  -?, --help Show this help message
  --usage Displa...

Read more...

Revision history for this message
Martin Steigerwald (ms-proact) wrote :

I believe the offending code to be in "_write_network" in /usr/lib/python2.7/site-packages/cloudinit/distros/rhel.py

Changed in cloud-init (CentOS):
importance: Unknown → Undecided
status: Unknown → Confirmed
Revision history for this message
Ryan Harper (raharper) wrote :

Hi,

Thanks for filing a bug. Can you provide the version of cloud-init you're using?
You might give the our daily centos build a try to see if this resolves your issue.

https://copr.fedorainfracloud.org/coprs/g/cloud-init/cloud-init-dev/

I've not seen cloud-init render sysconfig files with the /CIDR suffix, we generally will use NETMASK value instead:

If I take your provided network-config and have cloud-init write it out on centos; this is the file we create:

(neipa) cloud-init % cat test-centos-ipaddr/etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=10.0.0.4
HWADDR=F2:15:C8:E1:0A:49
IPADDR=10.0.88.151
NETMASK=255.0.0.0
NM_CONTROLLED=no
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no
(neipa) cloud-init % PYTHONPATH=`pwd` python3 -m cloudinit.cmd.main devel net-convert -p network_configs/centos-ipaddr-prefix.yaml --kind yaml --distro centos -O sysconfig -d test-centos-ipaddr
Read input format 'yaml' from 'network_configs/centos-ipaddr-prefix.yaml'.
Wrote output format 'sysconfig' to 'test-centos-ipaddr/'

(neipa) cloud-init % cat test-centos-ipaddr/etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=10.0.0.4
HWADDR=F2:15:C8:E1:0A:49
IPADDR=10.0.88.151
NETMASK=255.0.0.0
NM_CONTROLLED=no
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no

Changed in cloud-init:
status: New → Incomplete
Revision history for this message
Martin Steigerwald (ms-proact) wrote :

Hi Ryan.

Whoa, this bug is quite old already. I do not see this behavior anymore. Cloud Init in my current CentOS 7.6 images works as it should.

Thus this can be closed. Thank you.

Revision history for this message
Martin Steigerwald (ms-proact) wrote :

Ah, JFYI: It is using NETMASK= here as well meanwhile.

Revision history for this message
Chad Smith (chad.smith) wrote :

Excellent, ok leaving this bug as INVALID then. If the problem is still exhibited on latest cloud-init please re-open and provide the failing cloud-init version.

If your image doesn't contain cloud-init version 19.2 or later, Latest cloud-init for centos is here available here https://copr.fedorainfracloud.org/coprs/g/cloud-init/cloud-init-dev/

Changed in cloud-init:
status: Incomplete → Invalid
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.