How to automatically identify which network card the pve web page is using in the script

saberlion

New Member
Mar 15, 2022
4
0
1
29
I want to use pve as the underlying system of the two nas in my home (vm is truenas scale). I am writing an automatic deployment script to configure another nas and to reinstall in the future when the system disk is damaged or the system crashes, but I've run into a few questions, I've googled a lot, but I can't seem to find the answer, so I want to ask for help:

Example for the situation:
When I installed the system, I specified a network port (eno1) as the management port. When installing the system, the pve installer will set this network port as the network port for accessing the web panel and ssh, and the linux bridge will use this network port to Bridge, if I configure the pci pass-through, then if I mistakenly pass the management port to it when I create the vm, the https://ip:8006 webpage will not be able to open

question:
1. If I accidentally pass eno1 directly to the vm (id: 100), the ssh and pve web pages cannot be accessed at this time, except after stopping the vm, delete the hostpci0 line in /etc/pve/qemu-server/100.conf other than restarting the system, is there any way I can restore the pve web page without restarting the system?(ifreload -a directly is useless after deleting hostpci0 line in the conf)

2. If I want to automatically identify which network port the pve web page is using in the script, so as to avoid this network port when adding a pass-through network port automatically, how should I know the name of this network port?(instead of check the value of bridge-ports in /etc/network/interfaces) (I only know how to get the corresponding relationship between id and network port name for the time being.)

Bash:
if ! "$(dpkg -l | grep -q sysfsutils)"; then apt install -y sysfsutils; fi
systool -c net | awk '/Class\ Device/{getline a;print $0,a}' | sed -e 's/Class Device/net_name/g' -e 's/Device/\|net_id/g' -e 's/[ ][ ]*//g' -e 's/\"//g' -e 's/$/\|/g' | grep "net_id"

Code:
net_name=eno1|net_id=0000:03:00.0|
net_name=enp1s0|net_id=0000:01:00.0|
net_name=enp2s0|net_id=0000:02:00.0|
net_name=enp4s0|net_id=0000:04:00.0|


For example information about a device(eno1 is the web port):


Bash:
root@pve:/etc/systemd# cat /etc/network/interfaces
auto lo
iface lo inet loopback

iface eno1 inet manual

auto vmbr0
iface vmbr0 inet static
        address 10.0.0.10/24
        gateway 10.0.0.1
        bridge-ports eno1
        bridge-stp off
        bridge-fd 0

iface enp1s0 inet manual

iface enp2s0 inet manual

iface enp4s0 inet manual


Any ideas will be appreciated
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!