Skip to content

Commit

Permalink
Improve hcloud server ssh command to use IPv6 automatically if no IPv…
Browse files Browse the repository at this point in the history
…4 is available. (#406)

Signed-off-by: Lukas Kämmerling <[email protected]>

Signed-off-by: Lukas Kämmerling <[email protected]>
  • Loading branch information
LKaemmerling authored Aug 16, 2022
1 parent 11e0413 commit 27b41d0
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions internal/cmd/server/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down

0 comments on commit 27b41d0

Please sign in to comment.