Second Default Gateway

I can manually add routes and rules, and everything works:

But when I try add rules & routes in the configuration it does not work.

Any tips?

1 Like

once you build the configutration,

whats ip link

netstat -r

ip route

just run a few diagnostic commands? Also is the VM, or bare metal?

are i see you are using funky route tables, this could be more tricky.

what exactly are you trying to achieve with these kool kid funky route tables.

1 Like


This is the goal: Two Default Gateways on One System - Thomas-Krenn-Wiki

As I said, it works if I manually run the commands…

I am running on metal.

Here are the commands after reboot (i.e. just using the config above).


Maybe a good idea to take this an a issue on github.

If you can give a list of imperative commands that your issuing on nixos, which makes this work, then please give them, and then the output of all the network diagnostic commands.

if you can the share the things you’ve tried in your configuration.nix.
and provide the same debug output.

It maybe that the module configures that network doesn’t have this capablity yet, or it’s just a misconfiguration of the modules somehow.

I’ll have a look if there is a nixos test that sets up a network like this as integration test.

if there isn’t one, as we can get this working, then i’d be up for writing an integration test.

nixos tests , are documentation at the end of the day.

interesting stuff, i wish i had a bit more time to take a look, i’m creating a startup at the moment, and i’m to the wall time wise… which is making me unhappy, because i like making nixers successful with nixos networking.

good luck!



I added an issue here: Add a Second Gateway - Networking Configuration · Issue #194893 · NixOS/nixpkgs · GitHub

Basically two issues:

  1. adding a default route to another table
  2. adding rules doesn’t seem to work…

I ended up doing a oneshot script. Not very elegant, but it works.

  # NTZ route through a physical tap and then out to AWS                                                                                                      networking = {
    iproute2 = {
      enable = true;
      rttablesExtraConfig =
        ''1 rt2'';
  }; = {
      wantedBy = [ "" ];
      after = [ "" ];
      description = "Upload files to cloud or MT ARCS etc.";
      path = [pkgs.bash pkgs.iproute];
      script = '' 
             ip route add default via dev eno3 table rt2                                                                                                    
             ip route add dev eno3 src table rt2                                                                                                
             ip rule add to table rt2                                                                                                                    
             ip rule add from table rt2
      serviceConfig = {
        Type= "oneshot";
        User = "root";
        Restart = "no";
1 Like