SSH - make permanent changes during shell login?

jonf

Dabbler
Joined
Jan 28, 2021
Messages
18
Recently I've been experimenting with shell/bash scripts in OPNsense (another BSD-based OS), so I thought I'd look at TrueNAS to see if I could come up with anything useful (possibly to automate later). But when I logged into my box via SSH I noticed it gave me this message in the console:

Warning: settings changed through the CLI are not written to the configuration database and will be reset on reboot.

Is there a way (e.g. a single command, or a series of commands) within the CLI (or via a shell script) to write such changes to this database to make them permanent, or can this only be done through the web GUI?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
This depends on what precisely you intend to change.
 

jonf

Dabbler
Joined
Jan 28, 2021
Messages
18
I was thinking of some network-related things, namely the gateway settings.

Reason: I recently enabled IPv6 on my home network (which is now running both v4 and v6), with the v6 LAN set to 'track interface' on my router (I'm new to IPv6, it was the first thing I read online that worked). Even if I set TrueNAS to 'auto-configure IPv6' I can't ping a v6 hostname from the console unless I also set the v6 gateway. I then set the v6 address of my router (the one that starts 2a00, the other one didn't seem to work) as the v6 gateway via the web GUI. What I've noticed is that if/when I reboot the router, this address changes (maybe it's because it's set to 'track interface'?); that means the only way I can get TrueNAS to connect again to IPv6 is to manually change this.

I found the following commands online which apparently can do this in a FreeBSD console...

route -6 add default <ipv6address> (if you don't already have one set)
route -6 change default <ipv6address> (if you want to change a pre-existing entry)

...but I don't know if this setting will survive a reboot given the aforementioned SSH warning, or even if it'll work in TrueNAS.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
You'll have to use the CLI middleware commands to ensure your settings end up in the config and will survive reboots. In your case, you'll need to run midclt call network.configuration.update '{"ipv6gateway": "<ipv6address>"}'.
 

jonf

Dabbler
Joined
Jan 28, 2021
Messages
18
You'll have to use the CLI middleware commands to ensure your settings end up in the config and will survive reboots. In your case, you'll need to run midclt call network.configuration.update '{"ipv6gateway": "<ipv6address>"}'.

Thanks, I'll save this for future reference
 

jonf

Dabbler
Joined
Jan 28, 2021
Messages
18
Rats, I'm close to getting my script working the way I want it to (including the aforementioned middleware command) but there's just one problem: I can't seem to get the IPv6 address from within my variable into the command. I get the following error in the console:

[EINVAL] global_configuration_update.ipv6gateway: '${routerip}' does not appear to be an IPv4 or IPv6 address

This is how I originally wrote it:

midclt call network.configuration.update '{"ipv6gateway": "${routerip}"}'

It doesn't seem to like the way in which I insert the variable (or it just doesn't like variables, I don't know :tongue:). I tried without the curly braces around the variable name (same error), and also without the double quotes around it (gave a bunch of what looked like some Python code errors). I tried searching online for the midclt command to see if there was some documentation, but I didn't find much (I'm guessing because it's particular to TrueNAS and maybe the devs don't want too much of it to be know publicly).

Any ideas?


Scratch that - I just managed to get it working as I was typing, by placing single quotes around the variable name within the double quotes:

midclt call network.configuration.update '{"ipv6gateway": "'${routerip}'"}'

Thanks again for the help.
 
Top