How to set values with UCI instead of LuCI (solved)

My goal is to set entry's with the same naming scheme with uci like it is done via LuCI.
This is an example for wireguard.

Of course I have read the doc's. But they are very unclear in this point.
Just to confuse beginners since the samples use other naming conventions then then web GUI ...
https://openwrt.org/docs/guide-user/base-system/uci
https://openwrt.org/docs/guide-user/services/vpn/wireguard/server

Global entries set by LuCI:

network.wg_srv0=interface
network.wg_srv0.proto='wireguard'
network.wg_srv0.private_key='mJBT9SSpC8+1J7te7iWifzbJ1RCSwCfuHLGbk+CwQEo='
network.wg_srv0.listen_port='12345'
network.wg_srv0.addresses='10.140.140.1/24' 'fdf1::1/64'

Peer 1 & 2 set by luci

network.@wireguard_wg_srv0[0]=wireguard_wg_srv0 network.@wireguard_wg_srv0[0].description='Peer1' network.@wireguard_wg_srv0[0].public_key='hLIRbZTClIDMEmjmdZkN3tyNRvOpcBV4crapB3OjcXg=' network.@wireguard_wg_srv0[0].allowed_ips='10.140.140.10/32' network.@wireguard_wg_srv0[1]=wireguard_wg_srv0 network.@wireguard_wg_srv0[1].description='Peer2' network.@wireguard_wg_srv0[1].public_key='hLIRbZTClIDMEmjmdZkN3tyNRvOpcBV4crapB3OjcXg=' network.@wireguard_wg_srv0[1].allowed_ips='10.140.140.12/32'

If the values are set via LuCI, I can change them with uci afterwards.

# uci set network.@wireguard_wg_srv0[0].allowed_ips="10.140.140.11/32"

I'm able to set the global entries by uci instead of LuCI. No problem so far.

# uci set network.wg_srv0="interface"
# uci set network.wg_srv0.proto="wireguard"
# uci set network.wg_srv0.private_key="mJBT9SSpC8+1J7te7iWifzbJ1RCSwCfuHLGbk+CwQEo="
# uci set network.wg_srv0.listen_port="12345"
# uci add_list network.wg_srv0.addresses="10.140.140.1/24"
# uci add_list network.wg_srv0.addresses="fdf1::1/64"

But I dont understand to add a peer with uci.
Let's try to add the first entry. The first line seems to be ok, since I got not error message.
But the second line gives me an error. Why that?

# uci set network.@wireguard_wg_srv0[0]=wireguard_wg_srv0
# uci set network.@wireguard_wg_srv0[0].description='Peer1'
uci: Invalid argument

When looking for the entries I get only the global values. No peer entries.
The first added line is not there ...

# uci show network |grep wg
network.wg_srv0=interface
network.wg_srv0.proto='wireguard'
network.wg_srv0.private_key='mJBT9SSpC8+1J7te7iWifzbJ1RCSwCfuHLGbk+CwQEo='
network.wg_srv0.listen_port='10000'
network.wg_srv0.addresses='10.140.140.1/24' 'fdf1::1/64'

So my final question is: How to add the peer (list) entries in LuCI style with uci?

Henning

1 Like
# Unnamed section
uci add network wireguard_vpn
uci set network.@wireguard_vpn[-1].public_key="..."

# Named section
uci set network.wgpeer1="wireguard_vpn"
uci set network.wgpeer1.public_key="..."

Both ways are valid, see also: WireGuard multi-client

1 Like

Ok,
I see the difference of the uci command's.
Did not realize that I have to add a network entry with different syntax first, when using the "unnamed" way like LuCI did.

@vgaetera
Thank you very much for pushing me to the right way.

Henning

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.