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
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.
Now, ensure systemd recognizes the changes and then test the service:
sudo systemctl daemon-reload sudo systemctl restart sshd.service
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.