What's new

Quick way to copy traffic routing rules from one ovpn client config to another

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Ian Macdonald

Occasional Visitor
I have an AC-86U and an OpenVPN client config (client 3) with 20+ tunnel routes. Now I want to create a second client config (client 5) that uses the same set of routes.

I really don't want to type all of those routes into the GUI a second time, so I thought I'd be clever and do it on the command line. After some poking around, I came up with the following:

Code:
for i in '' 1 2 3 4 5; do
  nvram set 'vpn_client_unit=3'
  foo="$(nvram get vpn_client_clientlist$i)"
  nvram set 'vpn_client_unit=5'
  nvram set "vpn_client_clientlist$i=$foo"
done

Unfortunately, setting vpn_client_unit isn't enough to switch to the right client config for reading or writing. Can anyone tell me what I'm missing here?

Additionally, if I manually set vpn_client_clientlist and vpn_client_clientlist[12345] to the right values, they don't stick and constantly revert to the old (blank) values. So I'm evidently missing something there, too. I thought nvram commit might be the answer here, but that doesn't help, either.

I'm not accustomed to reading and writing NVRAM on the command line, so I'm probably making a beginner's error somewhere in my expectations.
 
I have an AC-86U and an OpenVPN client config (client 3) with 20+ tunnel routes. Now I want to create a second client config (client 5) that uses the same set of routes.

I really don't want to type all of those routes into the GUI a second time, so I thought I'd be clever and do it on the command line. After some poking around, I came up with the following:

Code:
for i in '' 1 2 3 4 5; do
  nvram set 'vpn_client_unit=3'
  foo="$(nvram get vpn_client_clientlist$i)"
  nvram set 'vpn_client_unit=5'
  nvram set "vpn_client_clientlist$i=$foo"
done

Unfortunately, setting vpn_client_unit isn't enough to switch to the right client config for reading or writing. Can anyone tell me what I'm missing here?

Additionally, if I manually set vpn_client_clientlist and vpn_client_clientlist[12345] to the right values, they don't stick and constantly revert to the old (blank) values. So I'm evidently missing something there, too. I thought nvram commit might be the answer here, but that doesn't help, either.

I'm not accustomed to reading and writing NVRAM on the command line, so I'm probably making a beginner's error somewhere in my expectations.

The NVRAM variable names are wrong

e.g. try
Code:
foo=$(nvram get vpn_client${i}_clientlist)

nvram commit

P.S. Not sure if Base64 encoding is required for these fields on AC86U?...but you will soon spot it! ;)
 
Last edited:
The NVRAM variable names are wrong

e.g. try
Code:
foo=$(nvram get vpn_client${i}_clientlist)

nvram commit

P.S. Not sure if Base64 encoding is required for these fields on AC86U?...but you will soon spot it! ;)

Ha! I knew it would be something simple. Thank you very much.

So, the much simpler working solution is just this:

Code:
for i in '' 1 2 3 4 5; do
  nvram set "vpn_client5_clientlist$i=$(nvram get vpn_client3_clientlist$i)"
done

The commit isn't even needed.

I thought of the Base64 issue myself, but reasoned that the output of one config would probably work as the input of another, assuming that no implicit conversion takes place anywhere. At it turns out, though, Base64 isn't used at all.

Interestingly, the set of vpn_client_clientlist variables, i.e. with no client digit following the vpn_client portion, do also exist as variables, but setting them doesn't do anything. They appear to simply be duplicates of the variables belonging to whichever client config is currently selected in the GUI.
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top