After banging my head for about a day as to why a CentOS 7 VM created via the latest official cloud-init image just wouldn't have networking at all, on both a Proxmox 7 & a Proxmox 8 server with routed networking at Hetzner, here's a short guide that might benefit others...
As always, your mileage may vary.
First off, the VM would utilize a /29 subnet IP, so no need to hardcode the MAC address.
Secondly, the VM was created with "host" CPU type & VirtIO for networking ("eth0" used for the virtual NIC).
Now here comes the good stuff.
Once the VM was up, networking was just non-existent.
"ip a" returned the VM's loopback and eth0 configs (as you'd expect), but "ip route" was entirely empty.
Since the cloud-init image does not come with firewalld (in case that might cause an issue) or NetworkManager (which can be managed with nmtui quickly), our only configurations are essentially:
- /etc/resolv.conf
- /etc/sysconfig/network-scripts/ifcfg-eth0
THE RESOLVER
Although the cloud-init config was set to use the host's DNS settings, for some reason it had an internal IP as the first nameserver entry and then Hetzner's typical IPv4 nameservers. Using "vi" I updated it to:
Restart networking with:
THE NETWORK ADAPTER CONFIG
Checking out the /etc/sysconfig/network-scripts/ifcfg-eth0 file, it was properly configured by cloud-init.
So nothing more to do here.
THE ROUTES
Next step is to manually add our routes to the Proxmox IP which serves as the gateway for VMs:
Once we do that, we restore internet connectivity for the VM.
Just keep in mind that if you restart networking at this stage, you will lose these routes, so you need to re-add them.
If you don't intend on switching to NetworkManager, the next step is mandatory for these routes to stick across reboots and networking restarts:
- Create a file in /etc/sysconfig/network-scripts/ with the name pattern route-<device>. In my case, that was route-eth0.
- In that file add the following:
- If you reboot at this stage, your VM will come up with internet connectivity enabled and you can basically stop here if you like.
SWITCHING TO NETWORKMANAGER
Now's a good time to switch to the more modern NetworkManager, which just works better (e.g. there's no need to store into some file the routes added manually).
Update your system, install the relevant packages, disable "network" and enable "NetworkManager". It's best to perform these steps through the Proxmox VNC console:
Ensure our adapter is up (just in case) with:
Again, double-check /etc/resolv.conf for any corrections needed and then reboot.
Networking is now properly configured, using NetworkManager, in your cloud-init build CentOS 7 VM.
As always, your mileage may vary.
First off, the VM would utilize a /29 subnet IP, so no need to hardcode the MAC address.
Secondly, the VM was created with "host" CPU type & VirtIO for networking ("eth0" used for the virtual NIC).
Now here comes the good stuff.
Once the VM was up, networking was just non-existent.
"ip a" returned the VM's loopback and eth0 configs (as you'd expect), but "ip route" was entirely empty.
Since the cloud-init image does not come with firewalld (in case that might cause an issue) or NetworkManager (which can be managed with nmtui quickly), our only configurations are essentially:
- /etc/resolv.conf
- /etc/sysconfig/network-scripts/ifcfg-eth0
THE RESOLVER
Although the cloud-init config was set to use the host's DNS settings, for some reason it had an internal IP as the first nameserver entry and then Hetzner's typical IPv4 nameservers. Using "vi" I updated it to:
Bash:
nameserver 185.12.64.1
nameserver 185.12.64.2
Restart networking with:
Bash:
service network restart
THE NETWORK ADAPTER CONFIG
Checking out the /etc/sysconfig/network-scripts/ifcfg-eth0 file, it was properly configured by cloud-init.
So nothing more to do here.
THE ROUTES
Next step is to manually add our routes to the Proxmox IP which serves as the gateway for VMs:
Bash:
ip route add VM_GATEWAY_IP dev eth0
ip route add default via VM_GATEWAY_IP
Once we do that, we restore internet connectivity for the VM.
Just keep in mind that if you restart networking at this stage, you will lose these routes, so you need to re-add them.
If you don't intend on switching to NetworkManager, the next step is mandatory for these routes to stick across reboots and networking restarts:
- Create a file in /etc/sysconfig/network-scripts/ with the name pattern route-<device>. In my case, that was route-eth0.
- In that file add the following:
Bash:
ADDRESS0=VM_GATEWAY_IP
GATEWAY0=VM_GATEWAY_IP
NETMASK0=255.255.255.255
SWITCHING TO NETWORKMANAGER
Now's a good time to switch to the more modern NetworkManager, which just works better (e.g. there's no need to store into some file the routes added manually).
Update your system, install the relevant packages, disable "network" and enable "NetworkManager". It's best to perform these steps through the Proxmox VNC console:
Bash:
yum update
yum install epel-release
yum install NetworkManager
systemctl disable network
systemctl stop network
systemctl enable NetworkManager
systemctl start NetworkManager
Ensure our adapter is up (just in case) with:
Bash:
ip link set eth0 up
Again, double-check /etc/resolv.conf for any corrections needed and then reboot.
Networking is now properly configured, using NetworkManager, in your cloud-init build CentOS 7 VM.
Last edited: