diff --git a/src/cli/README.md b/src/cli/README.md index 164088742..ff5ebeba3 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -1063,6 +1063,17 @@ The parameters after `hostname` are optional. Any unspecified (or zero) value fo > DNS response for ipv6.google.com - 2a00:1450:401b:801:0:0:0:200e TTL: 300 ``` +The DNS server IP can be an IPv4 address, which will be synthesized to an IPv6 address using the preferred NAT64 prefix from the network data. + +> Note: The command will return `InvalidState` when the DNS server IP is an IPv4 address but the preferred NAT64 prefix is unavailable. + +```bash +> dns resolve example.com 8.8.8.8 +Synthesized IPv6 DNS server address: fdde:ad00:beef:2:0:0:808:808 +DNS response for example.com. - fd4c:9574:3720:2:0:0:5db8:d822 TTL:20456 +Done +``` + ### dns browse \ \[DNS server IP\] \[DNS server port\] \[response timeout (ms)\] \[max tx attempts\] \[recursion desired (boolean)\] Send a browse (service instance enumeration) DNS query to get the list of services for given service-name. @@ -1085,12 +1096,16 @@ instance2 Done ``` +> Note: The DNS server IP can be an IPv4 address, which will be synthesized to an IPv6 address using the preferred NAT64 prefix from the network data. The command will return `InvalidState` when the DNS server IP is an IPv4 address but the preferred NAT64 prefix is unavailable. + ### dns service \ \ \[DNS server IP\] \[DNS server port\] \[response timeout (ms)\] \[max tx attempts\] \[recursion desired (boolean)\] Send a service instance resolution DNS query for a given service instance. Service instance label is provided first, followed by the service name (note that service instance label can contain dot '.' character). The parameters after `service-name` are optional. Any unspecified (or zero) value for these optional parameters is replaced by the value from the current default config (`dns config`). +> Note: The DNS server IP can be an IPv4 address, which will be synthesized to an IPv6 address using the preferred NAT64 prefix from the network data. The command will return `InvalidState` when the DNS server IP is an IPv4 address but the preferred NAT64 prefix is unavailable. + ### dns compression \[enable|disable\] Enable/Disable the "DNS name compression" mode. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index d11f728ed..49760dc4f 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2945,17 +2945,24 @@ exit: otError Interpreter::GetDnsConfig(Arg aArgs[], otDnsQueryConfig *&aConfig) { // This method gets the optional DNS config from `aArgs[]`. - // The format: `[server IPv6 address] [server port] [timeout] + // The format: `[server IP address] [server port] [timeout] // [max tx attempt] [recursion desired]`. otError error = OT_ERROR_NONE; bool recursionDesired; + bool nat64SynthesizedAddress; memset(aConfig, 0, sizeof(otDnsQueryConfig)); VerifyOrExit(!aArgs[0].IsEmpty(), aConfig = nullptr); - SuccessOrExit(error = aArgs[0].ParseAsIp6Address(aConfig->mServerSockAddr.mAddress)); + SuccessOrExit(error = Interpreter::ParseToIp6Address(GetInstancePtr(), aArgs[0], aConfig->mServerSockAddr.mAddress, + nat64SynthesizedAddress)); + if (nat64SynthesizedAddress) + { + OutputFormat("Synthesized IPv6 DNS server address: "); + OutputIp6AddressLine(aConfig->mServerSockAddr.mAddress); + } VerifyOrExit(!aArgs[1].IsEmpty()); SuccessOrExit(error = aArgs[1].ParseAsUint16(aConfig->mServerSockAddr.mPort));