Skip to content

Instantly share code, notes, and snippets.

@clemone210
Last active October 11, 2023 15:00
Show Gist options
  • Save clemone210/bcfb814d38933ce5fd29dd680abe62cb to your computer and use it in GitHub Desktop.
Save clemone210/bcfb814d38933ce5fd29dd680abe62cb to your computer and use it in GitHub Desktop.
Netmaker / Netclient VPN error when using listen address

1. Create a Pre-Start Check Script

Firstly, create a script that will check if the desired IP address is available.

sudo nano /usr/local/bin/check_netmaker_ip.sh

Add the following content:

#!/bin/sh

# Wait for the netmaker interface to have the expected IP 
while ! ip addr show netmaker | grep -q "10.20.10.7"; do
    sleep 1 
done

exit 0

Note to change the IP to your host IP which is assigned by netmaker. After saving the file, make the script executable:

sudo chmod +x /usr/local/bin/check_netmaker_ip.sh

2. Modify the systemd Unit for sshd

You'll need to inform systemd to run the above script before attempting to start the SSH service.

sudo systemctl edit sshd.service

Add an ExecStartPre directive to the opened editor:

[Service] ExecStartPre=/usr/local/bin/check_netmaker_ip.sh

Save and exit.

3. Reload systemd and Test

Now, ensure systemd recognizes the changes and then test the service:

sudo systemctl daemon-reload sudo systemctl restart sshd.service

@clemone210
Copy link
Author

I had the issue on Ubuntu root server that when I only allow ssh on the netmaker ip address, that after a reboot, the server would not be accessible via ssh. The ssh service failed to start as during boot the netmaker service is not fully started.
With these changes the server is reachable by ssh on the netmaker ip after a reboot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment