# NetworkError: DNS lookup failed for host 'example.com'

- **ID:** `flutter/networkerror-dns-lookup-failed`
- **Domain:** flutter
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The device could not resolve the hostname to an IP address due to network connectivity issues, incorrect DNS configuration, or the host being unreachable.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Flutter 2.10 | active | — | — |
| Flutter 3.0 | active | — | — |
| Flutter 3.7 | active | — | — |

## Workarounds

1. **Check the device's network connectivity and retry with exponential backoff:
import 'dart:io';

Future<bool> checkConnectivity() async {
  try {
    final result = await InternetAddress.lookup('example.com');
    return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
  } on SocketException catch (_) {
    return false;
  }
}** (85% success)
   ```
   Check the device's network connectivity and retry with exponential backoff:
import 'dart:io';

Future<bool> checkConnectivity() async {
  try {
    final result = await InternetAddress.lookup('example.com');
    return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
  } on SocketException catch (_) {
    return false;
  }
}
   ```
2. **Use a custom DNS resolver or fallback to a different DNS server, e.g., Google's 8.8.8.8, by configuring the HttpClient:
HttpClient client = HttpClient();
client.findProxy = (uri) {
  return 'PROXY 8.8.8.8:53; DIRECT';
};** (75% success)
   ```
   Use a custom DNS resolver or fallback to a different DNS server, e.g., Google's 8.8.8.8, by configuring the HttpClient:
HttpClient client = HttpClient();
client.findProxy = (uri) {
  return 'PROXY 8.8.8.8:53; DIRECT';
};
   ```
3. **Implement a retry mechanism with a timeout and user-friendly error message:
try {
  await http.get(Uri.parse('https://example.com')).timeout(Duration(seconds: 10));
} on SocketException {
  // show error to user
}** (80% success)
   ```
   Implement a retry mechanism with a timeout and user-friendly error message:
try {
  await http.get(Uri.parse('https://example.com')).timeout(Duration(seconds: 10));
} on SocketException {
  // show error to user
}
   ```

## Dead Ends

- **Hardcoding IP addresses instead of hostnames** — IP addresses can change; not a scalable solution and may break on different networks. (50% fail)
- **Disabling DNS resolution and using raw IP in the app code** — Same as above; also violates best practices and may cause security warnings. (60% fail)
- **Assuming the error is always on the server side** — Often the client's DNS configuration or network is the issue; server may be fine. (40% fail)
