Uci command for static routing

Hi all!
Newbie question!

I need to add a static route to my interface: I did this via the LuCI interface, but I need to create a shell that get as arguments Ip,Sub, and Gateway and add the static route to the interface:
From /etc/config/network is see this:

        config route
	option interface 'wan'
	option target 'xxx.xxx.xxx.xxx'
	option netmask 'aaa.aaa.aaa.aaa'
	option gateway 'bbb.bbb.bbb.bbb'

As I said I would like to do this via a shell script.
I found this:

# uci add network route
# uci set network.@route[-1].interface=wan
# uci set network.@route[-1].target=xxx.xxx.xxx.xxx
# uci set network.@route[-1].netmask=aaa.aaa.aaa.aaa
# uci set network.@route[-1].gateway=bbb.bbb.bbb.bbb
# uci commit network

Not sure if it is correct before trying it :smiley:

Also what's @route[-1] stands for?

Thanks

It's the last route section, i.e. the one added in the uci add network route command.

You need to /etc/init.d/network reload, or you can use ubus to both commit and reload in one command: ubus call uci commit '{"config":"network"}'.

Ok thanks.
Question Nr.2 how to delete this route?

uci delete network route
/sbin/uci commit network

Correct?

no one?

Thanks

You have to specify the index when deleting unnamed sections.
Show route sections
uci show network|grep "@route\["
Delete one route:
uci delete network.@route[INDEX]

1 Like

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