Score:0

Can't persist default ip route on Ubuntu 20 (Hetzner cloud)

ck flag

I am using Hetzner cloud where I created 2 servers in a subnet (10.1.0.0/24) - one only with local ip, another one has public IP and is used as a NAT gateway for the first server.

On private server I configured an ip route

ip route add default via 10.1.0.1 dev enp7s0 onlink

Here is a resulting list of routes

root:~# ip route show

default via 10.1.0.1 dev enp7s0 onlink 
10.1.0.0/16 via 10.1.0.1 dev enp7s0 
10.1.0.1 dev enp7s0 scope link 
169.254.169.254 via 10.1.0.1 dev enp7s0 

DNS are configured in /etc/systemd/resolved.conf

[Resolve]
DNS=8.8.8.8 8.8.4.4

The problem is I can't persist default ip route so it is loaded after reboot. I tried using iptables-save but it doesn't output any routes, even those loaded at boot time (all except default).

I know that netplan is used and is configured somehow by Hetzner, as there is a stub file /etc/netplan/50-cloud-init.yaml though it doesn't has any network device config

Here is a list of network devices:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
 valid_lft forever preferred_lft forever
inet6 ::1/128 scope host 
valid_lft forever preferred_lft forever
2: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc fq_codel state UP group default qlen 1000
link/ether 86:00:00:2b:7f:7c brd ff:ff:ff:ff:ff:ff
inet 10.1.0.2/32 brd 10.1.0.2 scope global dynamic enp7s0
   valid_lft 84299sec preferred_lft 84299sec
inet6 fe80::8400:ff:fe2b:7f7c/64 scope link 
   valid_lft forever preferred_lft forever

Can I use it instead of default ip route to configure gateway? If yes, how?

us flag
`iptables-save` export IPTables rules into stdout. It does not save them in any file, and it does not help with routes. `ip route` is only a tool for runtime configuration. Persistent set up of network configuration is done via any networking toolset that is used on the server: Netplan, ifupdown etc. You need to find out which toolset is used on your server and change its configuration.
Vladyslav Melnychenko avatar
ck flag
@TeroKilkanen I was exporting with iptables-save to file, and the file was empty, default route wasn't there
us flag
As I told above, `iptables-save` only saves firewall rules. Routes are not in firewall rules.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.