简体   繁体   中英

Calling API by IP address vs domain name

During a recent DDoS attack on a DNS, my site was unable to continue to function.

While the main site remained up and running, I was unable to connect to an external API on a different domain, leading the site to become completely unusable.

The data is fetched using PHP:

file_get_contents(API_PATH)

I currently call the API using the domain name, but I'm able to use the IP address if required.

Are there any advantages/disadvantages of calling the API by IP?

Is there anything else I should be aware of before making this change?

Your machine probably cached the resolved host, and has not updated it yet. You would need to flush the DNS cache.

It is not a good idea to use an IP address. While the DNS provider might be attacked, it is more likely that the IP is changed. I mean, rarely is a DNS provider attacked in such a large scale like the recent one, and it is definitely more common to see a website to have its IP address changed (although it shouldn't always happen normally). Therefore, you may want to use an IP address during a DNS attack (although your own DNS provider might be attacked as well), but not as the normal condition. If you want to be safe, fallback to use a cached IP address if the domain fails to resolve; but writing that kind of code is meaningless anyway, since it is rarely useful.

If you use an IP address:

There really is not much difference in using the DNS name or IP address in your API calls.

However, If you ever change the service provider, you will have to update both your DNS settings (such as your A records) and the IP address in your code, you would not have to do this otherwise.

Other than that, pretty much good to go, unless someone else thinks of any other reason.

I assume you want to mitigate the impact of the recent DNS DDoS attacks.

Advantages:

  • Your website still functions. Although that may not matter too much because nobody will be able to even visit your website.

Disadvantages:

  • What if the API changes its IP address?
  • What if the API does load balancing using DNS (eg it may resolve to different IPs at different times)?
  • What if the API uses a CDN?

I do not recommend it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM