我正在运行 Arch Linux。重新启动后,由于网络尚未启动,sshd.service 无法启动。我必须手动运行:
sudo systemctl restart sshd
一旦我这样做了,sshd 服务就会启动,没有任何错误,并且运行正常。如何解决此问题,以便 systemd sshd.service 能够自动启动?
这是日志:
May 06 15:47:23 server2 nm-dispatcher[471]: req:3 'connectivity-change': completed: no scripts
May 06 15:47:23 server2 nm-dispatcher[471]: req:3 'connectivity-change': new request (0 scripts)
May 06 15:47:23 server2 NetworkManager[440]: <info> [1525636043.9284] manager: NetworkManager state is now CONNECTED_GLOBAL
May 06 15:47:22 server2 nm-dispatcher[471]: req:2 'up' [eth0]: completed: no scripts
May 06 15:47:22 server2 nm-dispatcher[471]: req:2 'up' [eth0]: new request (0 scripts)
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6632] manager: startup complete
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6626] device (eth0): Activation: successful, device activated.
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6566] policy: set 'Wired connection 1' (eth0) as default for IPv4 routing and DNS
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6565] manager: NetworkManager state is now CONNECTED_SITE
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6558] manager: NetworkManager state is now CONNECTED_LOCAL
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6557] device (eth0): state change: secondaries -> activated (reason 'none', sys-iface-state: 'manag>
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6555] device (eth0): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'manage>
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6549] device (eth0): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'managed')
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6541] dhcp4 (eth0): state changed unknown -> bound
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6536] dhcp4 (eth0): gateway 10.10.0.1
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6536] dhcp4 (eth0): hostname 'server2'
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6536] dhcp4 (eth0): domain name 'oaks'
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6536] dhcp4 (eth0): nameserver '10.10.0.1'
May 06 15:47:22 server2 dbus-daemon[439]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.Avahi.service': Unit dbus-org.freedesktop.Avahi.serv>
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6535] dhcp4 (eth0): expires in 648000 seconds
May 06 15:47:22 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.Avahi' unit='dbus-org.freedesktop.Avahi.service' requested >
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6535] dhcp4 (eth0): plen 24
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6535] dhcp4 (eth0): address 10.10.1.12
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6293] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6284] device (eth0): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6275] device (eth0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6262] manager: NetworkManager state is now CONNECTING
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6258] device (eth0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'manage>
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6251] device (eth0): Activation: starting connection 'Wired connection 1' (5b9f0bf9-ed10-31e5-bcad->
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6224] policy: auto-activating connection 'Wired connection 1'
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6206] device (eth0): state change: unavailable -> disconnected (reason 'carrier-changed', sys-iface>
May 06 15:47:22 server2 NetworkManager[440]: <info> [1525636042.6196] device (eth0): carrier: link connected
May 06 15:47:22 server2 kernel: IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
May 06 15:47:22 server2 kernel: e1000e: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: Rx/Tx
May 06 15:47:22 server2 udisksd[598]: udisks daemon version 2.7.6 starting
May 06 15:47:22 server2 systemd[1]: Starting Disk Manager...
May 06 15:47:20 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:20 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:20 server2 sshd[564]: fatal: Cannot bind any address.
May 06 15:47:20 server2 sshd[564]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:20 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:20 server2 systemd[1]: Stopped OpenSSH Daemon.
May 06 15:47:20 server2 systemd[1]: sshd.service: Scheduled restart job, restart counter is at 3.
May 06 15:47:20 server2 systemd[1]: sshd.service: Service hold-off time over, scheduling restart.
May 06 15:47:19 server2 systemd[1]: Startup finished in 12.430s (firmware) + 6.006s (loader) + 8.847s (kernel) + 2.106s (userspace) = 29.391s.
May 06 15:47:19 server2 polkitd[543]: Acquired the name org.freedesktop.PolicyKit1 on the system bus
May 06 15:47:19 server2 systemd[1]: Started Authorization Manager.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'org.freedesktop.PolicyKit1'
May 06 15:47:19 server2 polkitd[543]: Finished loading, compiling and executing 2 rules
May 06 15:47:19 server2 polkitd[543]: Error compiling script /etc/polkit-1/rules.d/40-allow-passwordless-printer-admin.rules
May 06 15:47:19 server2 polkitd[543]: Loading rules from directory /usr/share/polkit-1/rules.d
May 06 15:47:19 server2 polkitd[543]: Loading rules from directory /etc/polkit-1/rules.d
May 06 15:47:19 server2 polkitd[543]: Started polkitd version 0.114
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.9110] supplicant: wpa_supplicant running
May 06 15:47:19 server2 wpa_supplicant[546]: Successfully initialized wpa_supplicant
May 06 15:47:19 server2 systemd[1]: Started WPA supplicant.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'fi.w1.wpa_supplicant1'
May 06 15:47:19 server2 systemd[1]: Started CUPS Scheduler.
May 06 15:47:19 server2 colord[526]: failed to get session [pid 465]: No data available
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8565] device (wlan0): set-hw-addr: set MAC address to 02:6B:94:A4:D1:08 (scanning)
May 06 15:47:19 server2 kernel: IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8563] device (wlan0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'e>
May 06 15:47:19 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:19 server2 sshd[540]: fatal: Cannot bind any address.
May 06 15:47:19 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:19 server2 sshd[540]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:19 server2 systemd[1]: Starting WPA supplicant...
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8527] manager: (wlan0): new 802.11 WiFi device (/org/freedesktop/NetworkManager/Devices/3)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8521] device (wlan0): driver supports Access Point (AP) mode
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8519] wifi-nl80211: (wlan0): using nl80211 for WiFi device control
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='fi.w1.wpa_supplicant1' unit='wpa_supplicant.service' requested by ':1.1' (u>
May 06 15:47:19 server2 systemd[1]: Starting Authorization Manager...
May 06 15:47:19 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8493] manager: rfkill: WiFi now disabled by radio killswitch
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8492] rfkill1: found WiFi radio killswitch (at /sys/devices/pci0000:00/0000:00:1d.1/0000:05:00.0/ie>
May 06 15:47:19 server2 systemd[1]: Stopped OpenSSH Daemon.
May 06 15:47:19 server2 systemd[1]: sshd.service: Scheduled restart job, restart counter is at 2.
May 06 15:47:19 server2 systemd[1]: sshd.service: Service hold-off time over, scheduling restart.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.PolicyKit1' unit='polkit.service' requested by ':1.1' (uid=>
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.8479] ovsdb: Could not connect: No such file or directory
May 06 15:47:19 server2 kernel: IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
May 06 15:47:19 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:19 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:19 server2 sshd[525]: fatal: Cannot bind any address.
May 06 15:47:19 server2 sshd[525]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:19 server2 systemd[1]: Starting Manage, Install and Generate Color Profiles...
May 06 15:47:19 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:19 server2 systemd[1]: Stopped OpenSSH Daemon.
May 06 15:47:19 server2 systemd[1]: sshd.service: Scheduled restart job, restart counter is at 1.
May 06 15:47:19 server2 systemd[1]: sshd.service: Service hold-off time over, scheduling restart.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.ColorManager' unit='colord.service' requested by ':1.9' (ui>
May 06 15:47:19 server2 kernel: ath: Regpair used: 0x69
May 06 15:47:19 server2 kernel: ath: Country alpha2 being used: 00
May 06 15:47:19 server2 kernel: ath: EEPROM indicates we should expect a direct regpair map
May 06 15:47:19 server2 kernel: ath: EEPROM regdomain: 0x69
May 06 15:47:19 server2 kernel: IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6322] device (eth0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'ex>
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6298] settings: (eth0): created default wired connection 'Wired connection 1'
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6283] keyfile: add connection in-memory (5b9f0bf9-ed10-31e5-bcad-42dadabdcdad,"Wired connection 1")
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6253] manager: (eth0): new Ethernet device (/org/freedesktop/NetworkManager/Devices/2)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6223] manager: (lo): new Generic device (/org/freedesktop/NetworkManager/Devices/1)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6207] device (lo): carrier: link connected
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6185] Loaded device plugin: NMOvsFactory (/usr/lib/NetworkManager/libnm-device-plugin-ovs.so)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.6170] Loaded device plugin: NMTeamFactory (/usr/lib/NetworkManager/libnm-device-plugin-team.so)
May 06 15:47:19 server2 kernel: ath10k_pci 0000:05:00.0: htt-ver 3.47 wmi-op 4 htt-op 3 cal otp max-sta 32 raw 0 hwcrypto 1
May 06 15:47:19 server2 kernel: ath10k_pci 0000:05:00.0: Unknown eventid: 90118
May 06 15:47:19 server2 kernel: ath10k_pci 0000:05:00.0: Unknown eventid: 118809
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5679] Loaded device plugin: NMWifiFactory (/usr/lib/NetworkManager/libnm-device-plugin-wifi.so)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5647] Loaded device plugin: NMBluezManager (/usr/lib/NetworkManager/libnm-device-plugin-bluetooth.s>
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5550] Loaded device plugin: NMWwanFactory (/usr/lib/NetworkManager/libnm-device-plugin-wwan.so)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5299] Loaded device plugin: NMAtmManager (/usr/lib/NetworkManager/libnm-device-plugin-adsl.so)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5276] Loaded device plugin: NMVxlanDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5276] Loaded device plugin: NMVlanDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5276] Loaded device plugin: NMVethDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5276] Loaded device plugin: NMTunDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5276] Loaded device plugin: NMPppDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5276] Loaded device plugin: NMMacvlanDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] Loaded device plugin: NMMacsecDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] Loaded device plugin: NMIPTunnelDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] Loaded device plugin: NMInfinibandDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] Loaded device plugin: NMEthernetDeviceFactory (internal)
May 06 15:47:19 server2 nm-dispatcher[471]: req:1 'hostname': completed: no scripts
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] Loaded device plugin: NMDummyDeviceFactory (internal)
May 06 15:47:19 server2 nm-dispatcher[471]: req:1 'hostname': new request (0 scripts)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] Loaded device plugin: NMBridgeDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] Loaded device plugin: NMBondDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5275] dhcp-init: Using DHCP client 'internal'
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5274] manager: Networking is enabled by state file
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5274] manager: rfkill: WWAN enabled by radio killswitch; enabled by state file
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5273] manager: rfkill: WiFi enabled by radio killswitch; disabled by state file
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.5267] settings: loaded plugin iBFT: (c) 2014 Red Hat, Inc. To report bugs please use the NetworkMa>
May 06 15:47:19 server2 ntpd[458]: Command line: /usr/bin/ntpd -g -u ntp:ntp
May 06 15:47:19 server2 ntpd[458]: ntpd [email protected] Wed Mar 7 18:48:03 UTC 2018 (1): Starting
May 06 15:47:19 server2 systemd[1]: Started Network Manager Script Dispatcher Service.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
May 06 15:47:19 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:19 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:19 server2 sshd[463]: fatal: Cannot bind any address.
May 06 15:47:19 server2 sshd[463]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:19 server2 systemd[1]: Started Simple Desktop Display Manager.
May 06 15:47:19 server2 autossh[462]: ssh child pid is 476
May 06 15:47:19 server2 systemd[1]: Started Permit User Sessions.
May 06 15:47:19 server2 autossh[462]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[462]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[468]: ssh child pid is 475
May 06 15:47:19 server2 autossh[468]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[461]: ssh child pid is 474
May 06 15:47:19 server2 autossh[459]: ssh child pid is 473
May 06 15:47:19 server2 autossh[461]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[460]: ssh child pid is 472
May 06 15:47:19 server2 autossh[459]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[460]: starting ssh (count 1)
May 06 15:47:19 server2 systemd[1]: Starting Network Manager Script Dispatcher Service...
May 06 15:47:19 server2 autossh[466]: ssh child pid is 470
May 06 15:47:19 server2 autossh[466]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[468]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[461]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[459]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[460]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[466]: port set to 0, monitoring disabled
May 06 15:47:19 server2 systemd[1]: Starting Permit User Sessions...
May 06 15:47:19 server2 systemd[1]: Starting CUPS Scheduler...
May 06 15:47:19 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.ser>
May 06 15:47:19 server2 systemd[1]: Starting Network Time Service...
May 06 15:47:19 server2 systemd[1]: Reached target Network.
May 06 15:47:19 server2 systemd[1]: Started Network Manager.
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.4679] manager[0x5631afba8080]: rfkill: WWAN hardware radio set enabled
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.4678] manager[0x5631afba8080]: rfkill: WiFi hardware radio set disabled
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.4674] dns-mgr[0x5631afbc3130]: init: dns=default, rc-manager=symlink
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.4672] hostname: hostname changed from (none) to "server2"
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.4672] hostname: hostname: using hostnamed
May 06 15:47:19 server2 systemd[1]: Started Hostname Service.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'org.freedesktop.hostname1'
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=9 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input19
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=8 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input18
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=7 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input17
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=3 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input16
May 06 15:47:19 server2 systemd[1]: Starting Hostname Service...
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' re>
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.1725] manager[0x5631afba8080]: monitoring kernel firmware directory '/usr/lib/firmware'.
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.1684] Read config: /etc/NetworkManager/NetworkManager.conf (lib: 20-connectivity.conf)
May 06 15:47:19 server2 NetworkManager[440]: <info> [1525636039.1683] NetworkManager (version 1.10.6-3, Arch Linux) is starting... (for the first time)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event4 ( USB Keyboard)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event3 ( USB Keyboard)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event0 (Sleep Button)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event1 (Power Button)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event2 (Power Button)
May 06 15:47:19 server2 systemd-logind[441]: New seat seat0.
May 06 15:47:19 server2 systemd[1]: Reached target Timers.
May 06 15:47:19 server2 systemd[1]: Started Daily man-db cache update.
May 06 15:47:19 server2 systemd[1]: Started Daily verification of password and group files.
May 06 15:47:19 server2 systemd[1]: Started Daily Cleanup of Snapper Snapshots.
May 06 15:47:19 server2 systemd[1]: Started Daily autocommit of changes in /etc directory.
May 06 15:47:19 server2 systemd[1]: Starting Login Service...
May 06 15:47:19 server2 systemd[1]: Starting Network Manager...
May 06 15:47:19 server2 systemd[1]: Started D-Bus System Message Bus.
May 06 15:47:19 server2 systemd[1]: Reached target Basic System.
May 06 15:47:19 server2 systemd[1]: Reached target Sockets.
May 06 15:47:19 server2 systemd[1]: Listening on CUPS Scheduler.
May 06 15:47:19 server2 systemd[1]: Listening on D-Bus System Message Bus Socket.
May 06 15:47:19 server2 systemd[1]: Started Daily Cleanup of Temporary Directories.
May 06 15:47:19 server2 systemd[1]: Started Timeline of Snapper Snapshots.
May 06 15:47:19 server2 systemd[1]: Reached target Paths.
May 06 15:47:19 server2 systemd[1]: Started CUPS Scheduler.
May 06 15:47:19 server2 systemd[1]: Started Daily rotation of log files.
May 06 15:47:19 server2 systemd[1]: Reached target System Initialization.
May 06 15:47:19 server2 systemd[1]: Started Update UTMP about System Boot/Shutdown.
May 06 15:47:19 server2 systemd[1]: Starting Update UTMP about System Boot/Shutdown...
May 06 15:47:19 server2 systemd[1]: Started Create Volatile Files and Directories.
May 06 15:47:19 server2 systemd[1]: Starting Create Volatile Files and Directories...
May 06 15:47:19 server2 systemd[1]: Started Flush Journal to Persistent Storage.
May 06 15:47:18 server2 systemd[1]: Reached target Sound Card.
/usr/lib/systemd/system/sshd.service:
[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target
[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
# This service file runs an SSH daemon that forks for each incoming connection.
# If you prefer to spawn on-demand daemons, use sshd.socket and [email protected].
/etc/NetworkManager/NetworkManager.conf 为空,/etc/NetworkManager/conf.d/ 为空。
值得注意的日志条目:
- 5 月 6 日 15:47:22 server2 内核:e1000e:eth0 NIC 链路已启动 1000 Mbps 全双工,流量控制:Rx/Tx
- 5 月 6 日 15:47:19 server2 systemd[1]:sshd.service:失败,结果为“退出代码”。
- 5 月 6 日 15:47:19 server2 systemd[1]:达到目标网络。
看来系统在实际接口启动之前就已到达目标网络。这是如何解决的?
答案1
正如 AB 所示,您的 ssh 配置可能已调整为侦听特定 IP 地址。如果 sshd 启动时该 IP 地址不可用,则该服务将失败。
默认情况下,sshd 配置为 liste on 0.0.0.0
,这意味着任何地址,因此不依赖于可用的特定 IP。
有两种方法可以解决这个问题:
之后开始network-online.target
systemdnetwork-online.target
为需要网络完全启动(配置所有接口)的服务提供了一个单元。这样你就可以在配置好接口后让 sshd 在本机启动后启动
mkdir /etc/systemd/system/sshd.service.d
cat > /etc/systemd/system/sshd.service.d/network-online.conf <<EOF
[Unit]
After=network-online.target
EOF
systemctl daemon-reload
允许绑定到非本地地址
另一个选项是允许侦听主机上不存在的地址。
该解决方案是系统范围的,因此适用于任何服务,而不仅仅是 sshd。
echo 'net.ipv4.ip_nonlocal_bind = 1' > /etc/sysctl.d/99-nonlocal_bind.conf
systemctl restart systemd-sysctl.service
答案2
在 @phemmer 答案的基础上,我遇到了同样的问题,并通过添加来修复它
[Unit]
Wants=network-online.target
After=network-online.target
在 /etc/systemd/system/sshd.service.d
配置文件中。
还要确保为您的网络管理器启用了正确的等待服务,详细信息这里。例如:
$ systemctl is-enabled NetworkManager-wait-online.service systemd-networkd-wait-online.service
答案3
以上都不适合我。我使用 cronjob 解决了这个问题。
sudo crontab -e
然后加:
@reboot sleep 10; systemctl start sshd
答案4
如果您使用 NetworkManager,请尝试:
systemctl enable NetworkManager-wait-online.service
就我而言,覆盖不是答案的地方。关键是network.target
和的定义network-online.target
。我的预期是网络此时已连接;但这更意味着连接过程已经完成。换句话说,它可能仍在连接,并且还没有有效的互联网连接。
我发现的唯一可行的解决方案是从dhcpcd.service
NetworkManger 切换到。首先,您会遇到同样的问题,但现在您可以启用NetworkManager-wait-online.service
.它network.target
通过等待互联网连接可用来“修复” 。
但请注意,默认情况下未启用该服务是有原因的。作为副作用,它可能减慢启动速度如果设置网络连接需要很长时间。在我自己的用例中,机器通过 LAN 电缆连接,启动延迟可以忽略不计。但要注意这种副作用。