Comment 36 for bug 216847

Revision history for this message
That Man (thatmantheman1212) wrote :

I researched this issue for about 6+ hours or so and finally came across this thread. I have been able to solve the issue thanks to this thread.

# ENVIRONMENT INFO:
Ubuntu 20.04.2 LTS (Focal Fossa)
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020

# PROBLEM:
 Open /etc/ssh/sshd_config and add: "ListenAddress=192.168.5.123"
 The IP address specified is the local IP of the Ethernet adapter on the motherboard.

 # EXPECTED RESULT: Boot the server, and then be able to login to the specified IP address via SSH from a remote workstation.

 # ACTUAL RESULT: Boot the server, and I am unable to login to the specified IP address via SSH from a remote workstation.

 # NOTES: If I remove "ListenAddress=192.168.5.123" from sshd_config, reboot the server, then I am able to login via SSH from a remote workstation.

  If the server is already on, and I am logged in via SSH, and I add "ListenAddress=192.168.5.123" to sshd_config, and then I run "sudo systemctl restart sshd", and then I run "sudo systemctl status sshd", I see that sshd is listening to the IP address specified with no errors. I am then able to logout/login of the SSH session successfully.

  However, if I add "ListenAddress=192.168.5.123" to sshd_config, reboot the server, then I am unable to log into the server via SSH from a different workstation. When I check /var/log/auth.log I find this error:

   Apr 29 08:09:45 user sshd[1395]: error: Bind to port 12345 on 192.168.5.123 failed: Cannot assign requested address.
   Apr 29 08:09:45 user sshd[1395]: fatal: Cannot bind any address.

  This leads me to believe that sshd is attempting to bind to the Ethernet adapter's IP address BEFORE the Ethernet adapter receives its IP address from the DHCP server (I think). Thus resulting in this fatal error.

## SOLUTION:
 Open /etc/systemd/system/sshd.service and change:

  FROM:

   [Unit]
   After=network.target auditd.service

  TO:

   [Unit]
   After=network-online.target auditd.service

 See this article for details: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/#cutthecraphowdoimakesurethatmyservicestartsafterthenetworkisreallyonline

 With this configuration in place, I add "ListenAddress=192.168.5.123" to sshd_config, reboot the server, and then I am successfully able to login via SSH from a remote workstation.