Q: How to run configuration commands in operational mode or from bash script?


#1

Hi !

Is it possible to run configuration commands in operational mode? If yes, how?

I know its possible to run operational commands in configuration mode with “run”, yet I’m need the opposite.
Firewall and DNAT rules need to be changed upon calculations made by bash shell script.

Thanks in advance.


#2

Made this tricky stuff. Here is an example of executing commands of both operational and configuration modes. Scripts need to be executed as vyos user, not root! Enjoy.

#!/bin/bash
run=/opt/vyatta/bin/vyatta-op-cmd-wrapper
cfg=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper

$run show interfaces

$cfg begin

$cfg set firewall name FW_TEST description 'TEST FIREWALL'

$cfg set firewall name FW_TEST rule 6000 action accept
$cfg set firewall name FW_TEST rule 6000 state established enable
$cfg set firewall name FW_TEST rule 6000 state related enable

$cfg commit
$cfg end