Script to create an ipset of the MX Guarddog servers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Paul Git 730e3ef992 Corrected mistakes in README 1 year ago Corrected mistakes in README 1 year ago
ipset-mxgd.conf Added iptable rule code and changed to dig a single server 1 year ago Various improvements, no longer doing redundent processing 1 year ago


A Bash shell script which uses ipset and iptables to allow connections from MXGuardDog IP addresses published in a DNS TXT record.

The ipset command doesn’t work under OpenVZ. It works fine on dedicated and fully virtualized servers like KVM though.

What’s new

  • 2019-03-31: Initial public release

Quick start for Debian/Ubuntu based installations

  1. wget -O /usr/local/sbin/
  2. chmod +x /usr/local/sbin/
  3. mkdir -p /etc/ipset-mxgd; wget -O /etc/ipset-mxgd/ipset-mxgd.conf
  4. Modify ```ipset-mxgd.conf`` according to your needs. The default should suffice.
  5. apt-get install ipset
  6. Create the ipset mxgd and insert it into your iptables input filter (see below). After proper testing, make sure to persist it in your firewall script or similar or the rules will be lost after the next reboot.
  7. Auto-update the mxgd ip list using a cron job

First run, create the list

to generate the /etc/ipset-mxgd/ip-mxgd.restore

/usr/local/sbin/ /etc/ipset-mxgd/ipset-mxgd.conf

iptables filter rule

# Enable mxgd ip list
ipset restore < /etc/ipset-mxgd/ip-mxgd.restore
iptables -I INPUT 1 -m set --match-set mxgd src -j DROP

Make sure to run this snippet in a firewall script or just insert it to /etc/rc.local.

Cron job

In order to auto-update the MXGuardDog IP list, copy the following code into /etc/cron.d/update-mxgd. Don’t update the list too often or some blacklist providers will ban your IP address. Once a day should be OK though.

33 23 * * *      /usr/local/sbin/ /etc/ipset-mxgd/ipset-mxgd.conf

Check for dropped packets

Using iptables, you can check how many packets got dropped using the ip list:

user@server:~# iptables -L INPUT -v --line-numbers
Chain INPUT (policy DROP 60 packets, 17733 bytes)
num   pkts bytes target            prot opt in  out source   destination
1       15  1349 DROP              all  --  any any anywhere anywhere     match-set mxgd src