Setting eth0 with cloud-init in vSphere

Hello - I’ve got a bit of a head scratcher here. I’m deploying 4 routers into vsphere using terraform and cloud-init.

2 of those routers have no issues setting the eth0 interface IP address, but the other 2 never come up with an eth0 IP. All 4 routers have multiple interfaces and only the eth0 is having this issue. In each case (working or not working), I have set the eth0 interface for no DHCP.

Here is an example of the configuration:

#cloud-config
vyos_config_commands:

  • set service ssh disable-host-validation
  • set interfaces ethernet eth1 address ‘1.1.1.132/25’
  • set interfaces ethernet eth2 address ‘1.1.2.57/29’
  • set interfaces ethernet eth3 address ‘1.1.3.225/27’
  • del interfaces ethernet eth0 address ‘dhcp’
  • set interfaces ethernet eth0 address ‘1.1.4.130/25’
  • set protocols static route x.x.x.x/32 next-hop ‘w.w.w.w’
  • set protocols static route a.a.a.a/32 next-hop ‘w.w.w.w’
  • set protocols static route y.y.y.y/32 next-hop ‘w.w.w.w’
  • set protocols static route b.b.b.b/32 next-hop ‘w.w.w.w’
  • set protocols static route c.c.c.c/32 next-hop ‘w.w.w.w’
  • set protocols static route d.d.d.d/32 next-hop ‘w.w.w.w’
  • set protocols static route e.e.e.e/32 next-hop ‘w.w.w.w’
  • set protocols static route f.f.f.f/25 next-hop ‘w.w.w.w’
  • set protocols static route g.g.g.g/25 next-hop ‘w.w.w.w’
  • set protocols static route h.h.h.h/24 next-hop ‘w.w.w.w’
  • set service https listen-address 0.0.0.0 listen-port ‘443’
  • set service ssh port ‘22’
  • set system host-name ‘VR1’
  • set system login user vyos authentication encrypted-password password
  • set system login user root authentication encrypted-password password
  • set system name-server ‘x.x.x.x’
  • set system name-server ‘y.y.y.y’
  • set system name-server ‘a.a.a.a’
  • set system ntp server ‘b.b.b.b’
  • set system syslog host ‘c.c.c.c’
  • set service snmp trap-target ‘d.d.d.d.d’
  • set system syslog global facility all level ‘info’
  • set system syslog global facility protocols level ‘debug’

Like I said, this works fine on 2 routers, and not on the other 2 routers. All other commands work fine.

Any ideas?

Hi, @CreationLabs!

It would be good to start by analyzing the content of config files (including archive) in the /config/ directory, the /var/log/cloud-init.log file, and the sudo journalctl -b output. There must be an obvious difference between working and non-working VMs.
You may share this data here with us, so we can try to figure out the problem together if you want. Only pay attention, that it may contain sensitive content.

Thanks for the tips.

I checked all of that and it confirms my theory that the router is rejecting my eth0 configuration and continues with DHCP even though I disabled it. Later it rejects the eth0 IP configuration.

From journalctl -b:

Jan 04 15:35:02 vlab360-VR1 systemd[1]: Created slice system-dhclient.slice.
Jan 04 15:35:02 vlab360-VR1 systemd[1]: Starting DHCP client on eth0...
Jan 04 15:35:02 vlab360-VR1 systemd[1]: Started DHCP client on eth0.
Jan 04 15:35:02 vlab360-VR1 vyos-configd[689]: Can't configure both static IPv4 and DHCP address on the same interface
Jan 04 15:35:02 vlab360-VR1 vyos-configd[689]: Sending response 2
Jan 04 15:35:02 vlab360-VR1 sudo[1899]: pam_unix(sudo:session): session closed for user root
Jan 04 15:35:02 vlab360-VR1 dhclient-script-vyos[1923]: Current dhclient PID: 1921, Parent PID: 1919, IP version: 4, All dhclients for interface eth0: 933 1919 1921
Jan 04 15:35:02 vlab360-VR1 dhclient-script-vyos[1923]: Stopping dhclient with PID: 933, PID file: /run/dhclient.eth0.pid
Jan 04 15:35:02 vlab360-VR1 dhclient[1950]: Killed old client process
Jan 04 15:35:02 vlab360-VR1 dhclient[1919]: Killed old client process


Jan 04 15:35:03 vlab360-VR1 dhclient[1921]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
Jan 04 15:35:03 vlab360-VR1 vyos-configd[689]: Sending response 1

Jan 04 15:36:03 vlab360-VR1 dhclient[1921]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 1
Jan 04 15:36:04 vlab360-VR1 dhclient[1921]: No DHCPOFFERS received.
Jan 04 15:36:04 vlab360-VR1 dhclient[1921]: No working leases in persistent database - sleeping.
Jan 04 15:36:05 vlab360-VR1 dhclient-script-vyos[2606]: Current dhclient PID: 1921, Parent PID: 1, IP version: 4, All dhclients for interface eth0: 1921
Jan 04 15:36:05 vlab360-VR1 dhclient-script-vyos[2606]: Deleting search domains with tag "dhcp-eth0" via vyos-hostsd-client
Jan 04 15:36:05 vlab360-VR1 vyos-hostsd[687]: Request data: {"type": "search_domains", "op": "delete", "data": ["dhcp-eth0"]}
Jan 04 15:36:05 vlab360-VR1 vyos-hostsd[687]: Saving state to /run/vyos-hostsd/vyos-hostsd.state

From /config/cat config.boot:

}
interfaces {
    ethernet eth3 {
        address "2.2.2.2/25"
    }
    ethernet eth2 {
        address "3.3.3.3/25"
    }
    ethernet eth1 {
        address "2.2.2.2/27"
    }
    ethernet eth0 {

        address "4.4.4.4/29"
    }
    loopback     lo { }
}

So to me it appears that the configuration is there, but the router rejects it.

@zsdc and @Dmitry found the cause of the problem. The reason was the syntax of commands where “del” was used instead of “delete”.
Used:
del interfaces ethernet eth0 address ‘dhcp’
Should be corrected to:
delete interfaces ethernet eth0 address ‘dhcp’
Also, cloud-init will be applied only to the first boot.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.