[GH-ISSUE #5] Is there a way to implement failover if a primary server does not accept the request? #6

Closed
opened 2026-02-26 04:33:44 +03:00 by kerem · 12 comments
Owner

Originally created by @MostHated on GitHub (Sep 22, 2016).
Original GitHub issue: https://github.com/mageddo/dns-proxy-server/issues/5

Hello,
I was wondering if there was a way to have multiple A records for a domain, and then if it detects that the first proxy IP is down, it can then failover and send the request to the second A record IP in the records file?

Thanks!

Originally created by @MostHated on GitHub (Sep 22, 2016). Original GitHub issue: https://github.com/mageddo/dns-proxy-server/issues/5 Hello, I was wondering if there was a way to have multiple A records for a domain, and then if it detects that the first proxy IP is down, it can then failover and send the request to the second A record IP in the records file? Thanks!
kerem 2026-02-26 04:33:44 +03:00
Author
Owner

@mageddo commented on GitHub (Sep 22, 2016):

@MostHated If I understand you question you want to have many A records at records.json file.

I don't know if you have tested it but In fact this is possible and should be working (as I saw at the code). Because when the browser (or whatever) receive a A record list then it try one by one looking for a working record

It happen at the response.answer.push(dns[record.type](record)); instruction in resolveDnsLocally function in app.js file

If it is not working please let me know and if possible create a pull request fixing it :)

<!-- gh-comment-id:248991004 --> @mageddo commented on GitHub (Sep 22, 2016): @MostHated If I understand you question you want to have many `A` records at `records.json` file. I don't know if you have tested it but In fact this is possible and should be working (as I saw at the code). Because when the browser (or whatever) receive a `A` record list then it try one by one looking for a working record It happen at the `response.answer.push(dns[record.type](record));` instruction in **resolveDnsLocally** function in `app.js` file If it is not working please let me know and if possible create a pull request fixing it :)
Author
Owner

@MostHated commented on GitHub (Sep 23, 2016):

I will definitely have a go at it tomorrow and let you know, thank you much for the info!

<!-- gh-comment-id:249067290 --> @MostHated commented on GitHub (Sep 23, 2016): I will definitely have a go at it tomorrow and let you know, thank you much for the info!
Author
Owner

@mageddo commented on GitHub (Sep 23, 2016):

You are welcome

<!-- gh-comment-id:249078595 --> @mageddo commented on GitHub (Sep 23, 2016): You are welcome
Author
Owner

@MostHated commented on GitHub (Sep 23, 2016):

The best way to test I suppose would be to put in 2 A records, with the first one working and the second working but at a different IP, then take the first IP, change it so that it is not working, then it should still work because it ends up going to the second one automatically?

<!-- gh-comment-id:249185277 --> @MostHated commented on GitHub (Sep 23, 2016): The best way to test I suppose would be to put in 2 A records, with the first one working and the second working but at a different IP, then take the first IP, change it so that it is not working, then it should still work because it ends up going to the second one automatically?
Author
Owner

@mageddo commented on GitHub (Sep 23, 2016):

Of course, I think that is. Anyway if you are using linux you can use nslookup command to find what A records was returned from the DNS Server, something like bellow:

$ nslookup stackoverflow.com 
Server:     172.24.0.3
Address:    172.24.0.3#53

Non-authoritative answer:
Name:   stackoverflow.com
Address: 151.101.1.69
Name:   stackoverflow.com
Address: 151.101.193.69
Name:   stackoverflow.com
Address: 151.101.65.69
Name:   stackoverflow.com
Address: 151.101.129.69

or specifying what DNS Server you want to use

$ nslookup stackoverflow.com 172.24.0.3

As you can see stackoverflow.com have many servers to the same hostname, Google Chrome for example will try one by none

website ip extension shows what address Chrome have resolved at the domain.

Remember that Chrome have cache for DNS names, so CTRL + F5 is your friend

<!-- gh-comment-id:249192271 --> @mageddo commented on GitHub (Sep 23, 2016): Of course, I think that is. Anyway if you are using linux you can use `nslookup` command to find what `A` records was returned from the DNS Server, something like bellow: ``` $ nslookup stackoverflow.com Server: 172.24.0.3 Address: 172.24.0.3#53 Non-authoritative answer: Name: stackoverflow.com Address: 151.101.1.69 Name: stackoverflow.com Address: 151.101.193.69 Name: stackoverflow.com Address: 151.101.65.69 Name: stackoverflow.com Address: 151.101.129.69 ``` or specifying what DNS Server you want to use ``` $ nslookup stackoverflow.com 172.24.0.3 ``` As you can see **stackoverflow.com** have many servers to the same hostname, Google Chrome for example will try one by none [website ip extension](https://chrome.google.com/webstore/detail/website-ip/ghbmhlgniedlklkpimlibbaoomlpacmk) shows what address Chrome have resolved at the domain. Remember that Chrome have **cache** for DNS names, so **CTRL + F5** is your friend
Author
Owner

@MostHated commented on GitHub (Sep 23, 2016):

When I do both dig and nslookup for it, I get

`Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
Name: mysite.com
Address: 1.1.1.1
`
but, when I go to actually type the address in the browser, I never see the hit reach my server of 1.1.1.1, it seems to never leave the DNS box, to hit my web hosting box.

Am I supposed to also have these entries here? Here is what my file looks like just trying to get it to work normally.
[
{
"records": [
{
"type": "A",
"address": "1.1.1.1",
"ttl": 300,
"name": "mysite.com"
}
],
"domain": "mysite.com"
},
{
"records": [
{
"type": "A",
"address": "127.0.0.1",
"ttl": 300
"name": "ns1.mysite.com"
}
],
"domain": "ns1.mysite.com"
}
,
{
"records": [
{
"type": "A",
"address": "127.0.0.1",
"ttl": 300
"name": "ns2.mysite.com"
}
],
"domain": "ns2.mysite.com"
}
]
As I have my DNS servers from my actual domain host pointed to this server

<!-- gh-comment-id:249228759 --> @MostHated commented on GitHub (Sep 23, 2016): When I do both dig and nslookup for it, I get `Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: mysite.com Address: 1.1.1.1 ` but, when I go to actually type the address in the browser, I never see the hit reach my server of 1.1.1.1, it seems to never leave the DNS box, to hit my web hosting box. Am I supposed to also have these entries here? Here is what my file looks like just trying to get it to work normally. [ { "records": [ { "type": "A", "address": "1.1.1.1", "ttl": 300, "name": "mysite.com" } ], "domain": "mysite.com" }, { "records": [ { "type": "A", "address": "127.0.0.1", "ttl": 300 "name": "ns1.mysite.com" } ], "domain": "ns1.mysite.com" } , { "records": [ { "type": "A", "address": "127.0.0.1", "ttl": 300 "name": "ns2.mysite.com" } ], "domain": "ns2.mysite.com" } ] As I have my DNS servers from my actual domain host pointed to this server
Author
Owner

@mageddo commented on GitHub (Sep 23, 2016):

Ok.. Are you checking the logs? They say that dig is asking dns-proxy-server ? Are you running from docker or with npm?

Looks like dig is not resolving from dns-proxy-server because his say that have used 8.8.8.8.

if you runned it from npm make sure that your /etc/resolv.conf have something like that:

nameserver 127.0.0.1 

Also make sure that you are running npm start as sudo.

Any way I think that your records.json need to looks like that

[
    {
        "records": [
            {
                "type": "A",
                "address": "1.1.1.1",
                "ttl": 300,
                "name": "mysite.com"
            },
            {
                "type": "A",
                "address": "1.1.1.2",
                "ttl": 300,
                "name": "mysite.com"
            }
        ],
        "domain": "mysite.com"
    }
]
<!-- gh-comment-id:249249586 --> @mageddo commented on GitHub (Sep 23, 2016): Ok.. Are you checking the logs? They say that **dig** is asking **dns-proxy-server** ? Are you running from docker or with npm? Looks like **dig** is not resolving from **dns-proxy-server** because his say that have used `8.8.8.8`. if you runned it from **npm** make sure that your `/etc/resolv.conf` have something like that: ``` nameserver 127.0.0.1 ``` Also make sure that you are running `npm start` as sudo. Any way I think that your **records.json** need to looks like that ``` [ { "records": [ { "type": "A", "address": "1.1.1.1", "ttl": 300, "name": "mysite.com" }, { "type": "A", "address": "1.1.1.2", "ttl": 300, "name": "mysite.com" } ], "domain": "mysite.com" } ] ```
Author
Owner

@MostHated commented on GitHub (Sep 26, 2016):

I am using npm, I was doing the command "dig mysite.com @127.0.0.1", I made sure to change my nameserver to 127.0.0.1 as well

<!-- gh-comment-id:249588803 --> @MostHated commented on GitHub (Sep 26, 2016): I am using npm, I was doing the command "dig mysite.com @127.0.0.1", I made sure to change my nameserver to 127.0.0.1 as well
Author
Owner

@mageddo commented on GitHub (Sep 26, 2016):

Anyway it is not working?

<!-- gh-comment-id:249701948 --> @mageddo commented on GitHub (Sep 26, 2016): Anyway it is not working?
Author
Owner

@mageddo commented on GitHub (Sep 26, 2016):

If not please describe your problem as below, then I will test it and mark as bug and try to solves.
I know that is boring to describe but is good to make sure that we are talking about the same thing .

The functionality with problem:
Expected behavior:
Currently behavior:
How simulate this scenario?:
Evidences: (print/output)

<!-- gh-comment-id:249714611 --> @mageddo commented on GitHub (Sep 26, 2016): If not please describe your problem as below, then I will test it and mark as bug and try to solves. I know that is boring to describe but is good to make sure that we are talking about the same thing . The functionality with problem: Expected behavior: Currently behavior: How simulate this scenario?: Evidences: (print/output)
Author
Owner

@MostHated commented on GitHub (Sep 29, 2016):

Sorry about this, I have been quite busy with work the last few days. I will try to get this information over to you as soon as I can!

Thanks for the assistance.

<!-- gh-comment-id:250547174 --> @MostHated commented on GitHub (Sep 29, 2016): Sorry about this, I have been quite busy with work the last few days. I will try to get this information over to you as soon as I can! Thanks for the assistance.
Author
Owner

@mageddo commented on GitHub (Sep 29, 2016):

No problem guy, ask as you need.

<!-- gh-comment-id:250600356 --> @mageddo commented on GitHub (Sep 29, 2016): No problem guy, ask as you need.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/dns-proxy-server-mageddo#6
No description provided.