Change gateway address?

I have a VPS that I’ve been running NixOS on for a while. Recently, the VPS provider changed servers, causing my VPS to get in a state that doesn’t work. I’m told by my VPS provider that I need to change the network gateway address. That this output:

$ ip r
default dev ens3 scope link src <WRONG-ADDRESS> metric 202

Is wrong and that I need to change the wrong address to the correct one (which I have been provided). How can I fix this? I’m currently connected to my NixOS VPS using VNC through the VPS providers website.

Do you use declarative networking or DHCP?

Thanks for responding! I have almost no network config in my configuration.nix. I have this:

  networking.hostName = "myhostname";
  networking.firewall.allowPing = true;
  networking.firewall.allowedTCPPorts = [ 80 443 ];

And to complicate matters I’m currently not able to rebuild using sudo nixos-rebuild build at all, since I can’t access the internet from the VPS.

As you have access via the console, restart dhcpd.service or reboot to get a new lease.

I did a systemctl restart dhcpcd.service, but from what I can see from systemctl status dhcpcd.service it’s just getting the wrong address again?



The gateway address that I want is

To further complicate things I can’t rebuild nixos on the VPS itself because it doesn’t have enough memory.

The problem doesn’t seem to be the gateway IP.

I now realise, that the default route is using the device ens3, without a configured target IP. the is the IP to be used as src IP.

In the worst case you need to manually invoke some ip r change default … to get the route set up correctly, at least temporary.

So far I never had a problem like this, that hasn’t been solved by a reboot…

Thanks again for responding. I’ve tried a bunch of different versions of ip r add default via __ types of commands, but no luck so far. If anyone has tutorials to suggest I’d welcome that.

I figured this out eventually. I saw this in the logs, using journalctl:

Mar 23 11:41:06 myhostname dhcpcd[1142]: ens3: failed to renew DHCP, rebinding
Mar 23 11:41:06 myhostname dhcpcd[1142]: ens3: router <gateway-ip> requires a host route

I tried to do

systemctl restart dhcpcd.service
systemctl status dhcpcd.service

That told me:

Mar 23 12:27:58 myhostname dhcpcd[2998]: ens3: leased <my-ip> for 14400 seconds
Mar 23 12:27:58 myhostname dhcpcd[2998]: ens3: router <gateway-ip> requires a host route

14400 seconds is 4 hours, and after each restart of my VPS it was indeed available for about 4 hours. After my hosting provider changed some dhcp settings, and I upgraded nixos, the dhcp lease increased significantly - solving the problem :slight_smile: