How to create default route for custom routing table via uci

I created a custom routing table (num: "22" name: "table_name") in /etc/iproute2/rt_tables.

root@192.168.1.1:~# cat /etc/iproute2/rt_tables
#
# reserved values
#
128     prelocal
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
22      table_name

I trying to set a default route for this table. If I execute the following commands, it fixes my routing issue:

ip route add <ip_address> dev <if_name> table <table_name> 
ip route add default via  <ip_address> table <table_name> 
ip route flush cache

However, this "fix" reverts on boot, so I'd like to make it survive the next boot.

How do I setup the default route for an interface in the custom table, replicating the ip commands above, using uci commands?

I see in the pbr_extras there is a set network.default'${IPV%4}' command, but I'm not sure how to use it and can't find any references online. Also, it probably requires pbr to be installed.

Than you in advance.

Look closely its an embedded uci script as here document.

In addition you can set routes and rules via UCI config files too.

and

1 Like

Some examples see paragraph about Creating routing tables in WireGuard Policy Based Routing (PBR)

#in /etc/config/network

config route
        option target '<ip_address>'
        option interface '<if_name>'
        option table '22' #or 'table_name'

config route
        option target '0.0.0.0'
        option netmask '0.0.0.0'
        option gateway '<gateway_ip_address>'
        option table '22' #or 'table_name'
        # option interface '<if_name>'
2 Likes