Add default gateway

Hi,

I’m using the wlan0 connection (in hotspot mode) and some other device as internet gateway. In order for this to work I have to do
route add default gw 192.168.42.20 (the ip of the gateway device)
This works perfectly but my application requires that this is made automatically while booting. So, my question is: How do I make this persistent over reboot?

Thanks in advance.
Best regards,

Santiago

Hi,

This type of stuff on Reach is handled by systemd-networkd. You have two options:

  • Create a systemd service, which will execute your command every boot
  • Or add a config file to /etc/systemd/network, some examples here.
1 Like

Thanks!!

Would you mind sharing your solution?

Of course, my bad.
I created the file /etc/systemd/network/wlan0.network with the following lines:

[Match]
Name= wlan0

[Network]
Adress= 192.168.42.1
Gateway= 192.168.42.20

Note that my aplication needs the IP to be fixed, for DHCP the solution may vary.

Best regards,
Santiago

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.