5

I am trying to make autossh set up a reverse tunnel to a server I have at home automatically with systemd. I set up a unit in /etc/systemd/system called autossh.service

It all works fine if I start the service once I am connected to the Internet. However, that is not the case on startup. It fails saying "Could not resolve hostname" since it is not connected to the Internet.

In /etc/systemd/system/autossh.service I have the line

After=network-online.target

which should in theory take care of this problem but it doesn't. The command fails on startup (it is not online yet so it says it could not resolve the hostname) and it does not try again.

How can I solve this?

5 Answers 5

3
+100

Something like:

Restart=always
RestartSec=120

Maybe...

Or see: systemd service automatic restart after StartLimitInterval

3

a) Try adding StartLimitIntervalSec=12 in [Unit] at the begining of autossh.service.

b) And Type=simple at [Service] part.

c) Reload daemon sudo systemctl daemon-reload.

d) Reenable it sudo systemctl enable autossh.

e) Start it sudo systemctl start autossh.

f) Reboot

Did it worked out?

2

You should also add:

Wants=network-online.target

This will ensure that all configured network devices are up and have an IP address assigned before the service is started.

1
0

Use crontab for this if you have cronie installed it will be executed later then your hostname being found.

Edit your cronie by:

crontab -e 

.. Now add below command in your editor, reboot PC and have fun!

@reboot autossh ..... OR /path/to/some/script
0

Doesn't this sound like a better target to have your unit file wait for?

nss-lookup.target

A target that should be used as synchronization point for all host/network name service lookups. Note that this is independent of UNIX user/group name lookups for which nss-user-lookup.target should be used. All services for which the availability of full host/network name resolution is essential should be ordered after this target, but not pull it in. systemd automatically adds dependencies of type After= for this target unit to all SysV init script service units with an LSB header referring to the "$named" facility.

ref

1
  • Seem good but no differences after add it in my service file dependency. always error: janv. 31 10:43:36 nano002 autossh[4512]: ssh: Could not resolve hostname
    – themadmax
    Jan 31, 2020 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .