Problem
When you need to change the network configuration of your Proxmox hosts you probably want to do that via the web interface. Most of the times. But then there are situations when you need to make changes directly to the /etc/network/interfaces file for example. Like when you need to add post-up iptable commands. Then you also need to apply these changes via command line. From what I experienced it is a good practice to align this procedure with the way Proxmox would do this when you use the web interface.
Solution
Create a script that uses Proxmox’ internal workflows to apply changed network configurations. Therefore the script copies /etc/network/interfaces file (where you made all your changes to the config) to /etc/network/interfaces.new and restarts the networking service. Proxmox will then grab the /etc/network/interfaces.new file and apply its content to the network infterfaces.
The script itself is created in a directory that is contained in the $PATH environment variable so one can call it from anywhere without remembering the complete path to the script.
Here are the steps to use the script:
# Create the script with the content from the section at the bottom of this page $ sudo nano /usr/local/bin/apply_pve_network_config # Make the script executable $ sudo chmod +x /usr/local/bin/apply_pve_network_config # Call the script $ apply_pve_network_config
Here is the content of the script:
#!/bin/bash # Test for sufficient priviliges if ! [ -w "/etc/network/interfaces" ] then printf "[\e[31m-\e[0m] Please run this script as a privileged user (i.e. with the help of sudo)\n" exit 1 else printf "Restarting network ...\n" fi # Use Proxmoxes toolchain to apply a changed configuration cp /etc/network/interfaces /etc/network/interfaces.new systemctl restart networking.service printf "[\e[32m+\e[0m] Configuration updated.\n" exit 0
Software Versions used
- Proxmox: 7.1