# DNS Service does not randomize IP addresses

**URL:** <https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666>\
**Category:** Rancher 1.x\
**Created:** [February 27, 2017, 12:04pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666 "2017-02-27T12:04:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![NarunasK](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@NarunasK](https://forums.suse.com/u/NarunasK)\
**Post date:** [February 27, 2017, 12:04pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/1 "2017-02-27T12:04:17Z")

</div>

It seems that _DNS Service_ does not work in a way [documentation](http://docs.rancher.com/rancher/v1.4/en/rancher-services/dns-service/) prescribes it:

> When queried by the service name, the DNS service returns a randomized list of IP addresses of the healthy containers implementing that service.

I’ve created `Nginx` stack, added `nginx` service and created `lb-test` load balancer for this service.

I then created a different stack, added `debian` service and linked `lb-test` from `nginx` service as `nginx-lb` in the `debian` service.

Below are my results, it seems that IPs are not randomized and always returned in the same order:

```
root@4a398d57a8ab:~# for _ in {1..4}; do echo '~/~'; getent hosts nginx-lb; sleep 1; done
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
~/~
10.42.67.172 nginx-lb.rancher.internal
10.42.180.18 nginx-lb.rancher.internal
root@4a398d57a8ab:~# for _ in {1..4}; do echo '~/~'; getent hosts lb-test.nginx; sleep 1; done
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx
~/~
10.42.67.172 lb-test.nginx
10.42.180.18 lb-test.nginx

```

In comparison with `AWS` I have expected that returned list of IP addresses will be _rotated in a round robin_ fashion.

A simple application simulation:

```
root@4a398d57a8ab:~# for _ in {1..30}; do curl -sv lb-test.nginx 2>&1 | grep 'Connected to'; done
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
* Connected to lb-test.nginx (10.42.180.18) port 80 (#0)
root@4a398d57a8ab:~# for _ in {1..30}; do curl -sv nginx-lb 2>&1 | grep 'Connected to'; done
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)
* Connected to nginx-lb (10.42.180.18) port 80 (#0)

```

Each time my application (curl script) has connected to the same `nginx` container (10.42.180.18).

Any ideas?

BTW, I’m using the following components:

```
Rancher	v1.4.1
Cattle	v0.176.9
User Interface	v1.4.6
Rancher CLI	v0.4.1
Rancher Compose	v0.12.2

```

---

<div class="post-metadata">

**Author:** ![sjiveson](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/sjiveson/32/966_2.png) [@sjiveson](https://forums.suse.com/u/sjiveson)\
**Post date:** [February 28, 2017, 1:05pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/2 "2017-02-28T13:05:06Z")

</div>

Just FYI, I did a test of this in my environment and saw the same behaviour. What I did notice was that a single container always seems to get the same response and record order but another container will get a different order (but again, always the same order). Perhaps a subtle change in behaviour that hasn’t been documented? It might be worth raising an issue on Github?

---

<div class="post-metadata">

**Author:** ![NarunasK](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@NarunasK](https://forums.suse.com/u/NarunasK)\
**Post date:** [February 28, 2017, 2:44pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/3 "2017-02-28T14:44:44Z")

</div>

Just opened new [issue](https://github.com/rancher/rancher/issues/7990), hopefully soon we will see what devs think about it.

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [February 28, 2017, 3:45pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/4 "2017-02-28T15:45:36Z")

</div>

The same people read the forum and github. Creating an issue with no info in it besides a link to the forum is just a waste of time and effort for all.

Responses are always randomized. Client software is not and some specifically in-randomize. DNS is not an effective load balancer, if you care about the balance of requests you need an internal balancer.

[https://github.com/rancher/rancher/issues/3495](https://github.com/rancher/rancher/issues/3495)

---

<div class="post-metadata">

**Author:** ![NarunasK](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@NarunasK](https://forums.suse.com/u/NarunasK)\
**Post date:** [February 28, 2017, 5:06pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/5 "2017-02-28T17:06:44Z")

</div>

Hopefully the following test can prove that regardless of the client Rancher DNS is not randomized.

Before I tested it on `debian` image, this time `busybox` was used:

Note that when I use AWS DNS, responses are rotated in round robin. When I restore original `resolv.conf`, thus internal Rancher DNS server is being used, DNS responses are all returned in the same order. Client is the same in both tests, the only changing component is DNS server.

```
/ # resolv=$(cat /etc/resolv.conf)
/ # echo 'nameserver 172.30.0.2' > /etc/resolv.conf
/ # for _ in $(seq 4); do echo '~/~'; nslookup $ADDR | grep -A2 Name: | awk '/Address/{split($3,ip,".");printf "X.X.X.%s\n",ip[3]}'; done
~/~
X.X.X.13
X.X.X.128
~/~
X.X.X.128
X.X.X.13
~/~
X.X.X.13
X.X.X.128
~/~
X.X.X.128
X.X.X.13
/ # echo "$resolv" > /etc/resolv.conf
/ # for _ in $(seq 4); do echo '~/~'; nslookup $ADDR | grep -A2 Name: | awk '/Address/{split($3,ip,".");printf "X.X.X.%s\n",ip[3]}'; done
~/~
X.X.X.13
X.X.X.128
~/~
X.X.X.13
X.X.X.128
~/~
X.X.X.13
X.X.X.128
~/~
X.X.X.13
X.X.X.128
/ # ADDR=nginx.nginx
/ # for _ in $(seq 4); do echo '~/~'; nslookup $ADDR | grep -A2 Name: | awk '/Address/{split($3,ip,".");printf "X.X.X.%s\n",ip[3]}'; done
~/~
X.X.X.139
X.X.X.7
~/~
X.X.X.139
X.X.X.7
~/~
X.X.X.139
X.X.X.7
~/~
X.X.X.139
X.X.X.7
```

---

<div class="post-metadata">

**Author:** ![RobertKozak](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/robertkozak/32/1481_2.png) [@RobertKozak](https://forums.suse.com/u/RobertKozak)\
**Post date:** [February 28, 2017, 5:34pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/6 "2017-02-28T17:34:02Z")

</div>

what’s your lease time?

---

<div class="post-metadata">

**Author:** ![NarunasK](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@NarunasK](https://forums.suse.com/u/NarunasK)\
**Post date:** [February 28, 2017, 6:04pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/7 "2017-02-28T18:04:52Z")

</div>

How is dhcp lease time relevant?

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [February 28, 2017, 7:10pm UTC](https://forums.suse.com/t/dns-service-does-not-randomize-ip-addresses/5666/8 "2017-02-28T19:10:38Z")

</div>

Apparently adding caching broke this a while ago, and the cache is client-specific.
