diff --git a/src/lib/ares_process.c b/src/lib/ares_process.c
index 87329e3..3caad1b 100644
--- a/src/lib/ares_process.c
+++ b/src/lib/ares_process.c
@@ -966,7 +966,7 @@ static int setsocknonblock(ares_socket_t sockfd,    /* operate on this */
 #endif
 }
 
-static int configure_socket(ares_socket_t s, int family, ares_channel channel)
+static int configure_socket(ares_socket_t s, int family, int style, ares_channel channel)
 {
   union {
     struct sockaddr     sa;
@@ -1009,6 +1009,20 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
   }
 #endif
 
+#ifdef __linux__
+  if(style == SOCK_DGRAM) {
+      int one = 1;
+      switch (family) {
+           case AF_INET:
+       (void) setsockopt (s, SOL_IP, IP_RECVERR, &one, sizeof (one));
+             break;
+          case AF_INET6:
+       (void) setsockopt (s, SOL_IPV6, IPV6_RECVERR, &one, sizeof (one));
+            break;
+        }
+  }
+#endif
+
   if (family == AF_INET) {
     if (channel->local_ip4) {
       memset(&local.sa4, 0, sizeof(local.sa4));
@@ -1082,7 +1096,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
     return -1;
 
   /* Configure it. */
-  if (configure_socket(s, server->addr.family, channel) < 0)
+  if (configure_socket(s, server->addr.family, SOCK_STREAM, channel) < 0)
     {
        ares__close_socket(channel, s);
        return -1;
@@ -1195,7 +1209,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
     return -1;
 
   /* Set the socket non-blocking. */
-  if (configure_socket(s, server->addr.family, channel) < 0)
+  if (configure_socket(s, server->addr.family, SOCK_DGRAM, channel) < 0)
     {
        ares__close_socket(channel, s);
        return -1;
