cloudflare/cloudflared · error

Invalid IP %s

Error message

Invalid IP %s

What it means

getRouteByIPCommand queries the Cloudflare API for the route associated with a given IP. The command takes exactly one argument that must parse as an IP address via net.ParseIP; when parsing fails (nil result), this error reports the invalid input.

Source

Thrown at cmd/cloudflared/tunnel/teamnet_subcommands.go:235

		return errors.Wrap(err, "API error")
	}
	fmt.Printf("Successfully deleted route with ID %s\n", routeId)
	return nil
}

func getRouteByIPCommand(c *cli.Context) error {
	sc, err := newSubcommandContext(c)
	if err != nil {
		return err
	}
	if c.NArg() != 1 {
		return errors.New("You must supply exactly one argument, an IP whose route will be queried (e.g. 1.2.3.4 or 2001:0db8:::7334)")
	}

	ipInput := c.Args().First()
	ip := net.ParseIP(ipInput)
	if ip == nil {
		return fmt.Errorf("Invalid IP %s", ipInput)
	}

	params := cfapi.GetRouteByIpParams{
		Ip: ip,
	}

	if c.IsSet(vnetFlag.Name) {
		vnetId, err := getVnetId(sc, c.String(vnetFlag.Name))
		if err != nil {
			return err
		}
		params.VNetID = &vnetId
	}

	route, err := sc.getRouteByIP(params)
	if err != nil {
		return errors.Wrap(err, "API error")
	}

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Supply a valid IP literal, e.g. `cloudflared tunnel route ip get 10.0.0.1`.
  2. If you have a CIDR to look up, strip or adjust the prefix to a concrete IP the route was created with.
  3. Resolve hostnames to IPs first (e.g. `dig +short host`) before passing them.

Example fix

// before
cloudflared tunnel route ip get example.com
// after
cloudflared tunnel route ip get 10.0.0.1
Defensive patterns

Strategy: validation

Validate before calling

ip := net.ParseIP(os.Args[len(os.Args)-1])
if ip == nil {
    return fmt.Errorf("%q is not a valid IP literal", os.Args[len(os.Args)-1])
}

Prevention

When it happens

Trigger: Running `cloudflared tunnel route ip get <arg>` where <arg> is not a valid IPv4/IPv6 literal — e.g. a hostname, a CIDR with unusual formatting, empty argument shaped like an IP, or a typo such as 1.2.3.256 or 2001:0db8:::7334-style typos.

Common situations: Passing a DNS name instead of an IP; passing a subnet like 10.0.0.0/8 (ParseIP rejects the /8 suffix); copy-paste artifacts; malformed IPv6 with too many '::' groups.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/ea99adfbd289d3c7. Report an issue: GitHub.