From c44700f2deed520949ef4a7f08603a70ea412bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Tue, 16 Aug 2022 12:44:51 +0200 Subject: [PATCH] Improve hcloud server ssh command to use IPv6 automatically if no IPv4 is available. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Kämmerling --- internal/cmd/server/ssh.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/internal/cmd/server/ssh.go b/internal/cmd/server/ssh.go index 6493fdd2..e40d7580 100644 --- a/internal/cmd/server/ssh.go +++ b/internal/cmd/server/ssh.go @@ -45,17 +45,13 @@ func runSSH(cli *state.State, cmd *cobra.Command, args []string) error { port, _ := cmd.Flags().GetInt("port") ipAddress := server.PublicNet.IPv4.IP - if useIPv6 { + if server.PublicNet.IPv4.IsUnspecified() || useIPv6 { if server.PublicNet.IPv6.IsUnspecified() { - return fmt.Errorf("server %s does not have a assigned primary ipv6", idOrName) + return fmt.Errorf("server %s does not have a assigned primary ipv4 or ipv6", idOrName) } ipAddress = server.PublicNet.IPv6.Network.IP // increment last byte to get the ::1 IP, which is routed ipAddress[15]++ - } else { - if server.PublicNet.IPv4.IsUnspecified() { - return fmt.Errorf("server %s does not have a assigned primary ipv4", idOrName) - } } sshArgs := []string{"-l", user, "-p", strconv.Itoa(port), ipAddress.String()}