block server access/connection to remote url

MaxFein

Member
Jul 29, 2015
20
2
3
Portland, Oregon
cPanel Access Level
Root Administrator
Hi, I'd like to block any access from my server to a specific url and am wondering the/a best way to go about this?

I have root access to my fully-managed VPS.

My host said that they add the url to be blocked by iptables.

However, looking online about using iptables this way shows that it can work but is perhaps not the best way... one person on serverfault put it this way:
" It's possible, but it's like trying to weld a Phillips bit on the side of a hammer so you can use it to drive screws."
...which is funny, hope you got a laugh too ;)

So, host says they can use the IP address currently associated with the URL so that iptables is better able to block outgoing connection for the time being... my concern is that the IP may change in future, which is why I want to just block the URL.

To be specific, I want to block connection to a specific URL (or is it URI?) that looks like this:

Code:
https://example.com/wp-admin/admin-ajax.php
(http:// equivalent also)

If its not practical to be so specific, I am fine blocking access to the domain name entirely.

Wondering if there is a way to do this by messing with DNS - eg. make it so that the server is not able (one way or another) to effectively resolve the name to an IP or some such... this is something like I would hack together on my PC via my hosts file... don't know enough about how to approach this with my server... :)

Any guidance appreciated, thanks very much.
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,216
463
Wondering if there is a way to do this by messing with DNS - eg. make it so that the server is not able (one way or another) to effectively resolve the name to an IP or some such... this is something like I would hack together on my PC via my hosts file... don't know enough about how to approach this with my server.
Hello,

You could modify the /etc/hosts file on your server, though keep in mind it's unsupported. It's one of the methods discussed on the following URL:

How to deny all the communications between our server and particular domain and its subdomains?

Thank you.
 
  • Like
Reactions: MaxFein

MaxFein

Member
Jul 29, 2015
20
2
3
Portland, Oregon
cPanel Access Level
Root Administrator
Hello,

You could modify the /etc/hosts file on your server, though keep in mind it's unsupported. It's one of the methods discussed on the following URL:

How to deny all the communications between our server and particular domain and its subdomains?

Thank you.
Thanks. While most of that thread is about blocking incoming by domain/URL and the challenges in *trying* to do that, I assume you are pointing toward the last answer on the thread:

Blocking outgoing on the other hand can be very simple - just add

127.0.0.1 example.com

to your hosts file (i.e. /etc/hosts) or a wildcard DNS record (*.example.com A 127.0.0.1) to your local DNS server and it will be enough to block outgoing connections (provided they use domain name to connect)
...
While /etc/hosts indeed is hackish (it doesn't support wildcart * after all), the "resolve via local DNS" solution is pretty solid, in fact it's the only way I can that will actually block *.example.com subdomains requests)
So yeah, that all makes good sense, and the question seems to be:

How to add a wildcard DNS record (*.example.com A 127.0.0.1) to the local DNS server on my server?

I'll google and check docs, etc... if you can save me some time re. what to edit and where, well, that'd be great :)

Cheers, Max
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,216
463
How to add a wildcard DNS record (*.example.com A 127.0.0.1) to the local DNS server on my server?
Hello,

You'd create a DNS zone for "example.com" using "WHM >> Add a DNS Zone" and then add the wildcard entry using "WHM >> Edit DNS Zone". However, I believe editing the /etc/hosts file on the server is the better approach as far as workarounds because outgoing connections may not always use the local server for DNS resolution.

Thank you.