what is the command to modify metric of an existing route entry in linux? I am able to change gateway of an existing entry using "ip route change" command as below but not able to change metrics. Is there any other command for that?

route –n   eth2

ip route change via

route -n   eth1
  • Here is a website page that has the commands to edit IP addresses using the ifconfig command. I don't know all the commands off the top of my head, but hopefully this page will help you. tecmint.com/ifconfig-command-examples Commented Nov 24, 2015 at 19:39
  • 1
    Delete the route and then add it again, unless they've since fixed lkml.iu.edu/hypermail/linux/net/0504.3/0017.html
    – thrig
    Commented Nov 24, 2015 at 19:58
  • 1
    I don't understand what your commands above are trying to show. In one you have a route on eth2 and the other on eth1. They're totally different. Commented Jul 6, 2022 at 21:42

4 Answers 4


(Combining various comments into an answer)

Currently, it is not possible to modify a route's metric. As a 2005 message on LKML states:

[...] The metric/priority cannot be changed because we do not have separate fields for the fields to match and the new values so if you specify a metric the entry simply won't be found and the request fails with ENOENT because NLM_F_CREATE is not specified. This is a limitation of the current protocol and it might be a good idea to to change this, however it's non trivial [...]

This seems to apply both to ip route change and ip route replace - the former results in an error for me, while the latter creates an additional route as advertised (its man page states that replace will replace or create a route). This is consistent with the kernel responding with ENOENT, and ip route replace following up with a route creation request.

So, the solution is to delete the existing route and add a new one. e.g.

ip route del via
ip route add via metric 1234
  • yes, got bitten by this problem this past few months... as Brian Cantrill keeps saying about Linux: It's an evolving thing with NIH (not invented here) syndrome...
    – Hvisage
    Commented Mar 12, 2019 at 8:48
  • @Hvisage can you elaborate? Is there any tool which allows to change the metric without having to remove it?
    – Braiam
    Commented Apr 23, 2019 at 19:43
  • @Braiam That is a negative, as in: NO such tool exists. as per the answer. If you refer to my Bryan Cantrill quotes, it was somewhere I believe in youtube.com/watch?v=wTVfAMRj-7E
    – Hvisage
    Commented Apr 24, 2019 at 20:28

ifmetric will allow you to change your route metric on the fly, given the interface the routes you want to change are going through.


ifmetric <iface> [<metric>]

For example, use ifmetric tun0 12 to change the metric to 12 for all routes going through tun0.


As noted in a comment to the question, quoting a message on the linux-net mailing list: "The metric/priority cannot be changed [...] This is a limitation of the current protocol [...]."
The only way is to delete the route and add a new one.

This is done using the route command, example:

sudo route add -net default gw netmask dev wlan0 metric 1

Debian manpage for the route command

  • 5
    The question wasn't how to add a route with a given metric; OP wanted to change the metric on an existing route (without deleting and re-adding the route). Commented Apr 6, 2018 at 18:55
  • 5
    Obviously you haven't read the comment in the question which links to the email showing that the metric can not be changed: The metric/priority cannot be changed [...] This is a limitation of the current protocol[...]. The only way is to delete the route and add a new one.
    – Jan
    Commented Apr 10, 2018 at 8:23
  • 8
    I know the metric can't be changed. Your answer still doesn't answer the question -- maybe point out, in the answer, that the metric can only be changed by deleting and re-adding the route? Commented Apr 18, 2018 at 8:34

It can be done by nmcli as mentioned below:-

nmcli connection modify ACTUAL_CONNECTION_NAME ipv4.route-metric 100
nmcli connection up ACTUAL_CONNECTION_NAME
  • This solution worked best for making this change persistent with future connections on my wwan0 link. Commented Oct 28, 2023 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .