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?