"Simple" script to disconnect/reconnect VM's Network Interface?

hvisage

Renowned Member
May 21, 2013
251
20
83
Good day,

I have some cases where I'd like to disconnect the VM(and some cases LXC)'s network interface, and after a while reconnect.
Okay, I can do it with 1,2,3,4<doubleCLick>5,6,7,8,[OK] clicks, (Rinse repeat to enable) but I'm looking for something I can script.

the `pvesh` method has the problem, that you need to: (a) fetch the -net interface's config, (b)find/append/change/remove the link_down=[01] option, and (c) write out the config.
The problem there is (a) & (b) as it seems the only way not to break the vlantag/bridge//MAC settings, is to follow the above

Anything I've missed?
 
What do you need to accomplish?

If it is only stopping all network activity, you can just activate and deactivate a firewall rule that blocks everything with pvesh.
 
What do you need to accomplish?

- To have a disconnect signal being sent to the VM's network, typically to enforce a dhcp renew/reload/etc.

If it is only stopping all network activity, you can just activate and deactivate a firewall rule that blocks everything with pvesh.

well... the first problem there is that it doesn't have any signal/feedback to the VM about the state of the interface that you can capture/respond to
 
I'm not sure about FortiGate, but pfSense is FreeBSD-based and there is a qemu guest agent available for that platform.
 
For FreeBSD yes, to get that easily installed into pfSense/opnSense/XigmaNAS/etc. is more than a simple "make install" as you would most probably need to setup a compile environment for them first.

FortiGate VMs are a contained environment

thus, it goes back to my question:

Is there a simple pvesh method to link_up/link_down?

At present the answer seems to be: "Nope, there aren't"
 
Anything I've missed?


Hi,

You can create a new briddge using a additional network iface on each Pmx node. On this iface you could run any script using ssh.

If you do not add a new iface/node, you can create a dummy iface and create a bridge using this dummy iface.

Good luck/Bafta!
 
Why not using the API to disconnect the virtual network adapter?
https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/config

Hmm.. let me check my original post:

the `pvesh` method has the problem, that you need to: (a) fetch the -net interface's config, (b)find/append/change/remove the link_down=[01] option, and (c) write out the config.
The problem there is (a) & (b) as it seems the only way not to break the vlantag/bridge//MAC settings, is to follow the above

The API method follows the same as pvesh, doesn't it?
Thus it is the same procedure?
 

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!