Skip to main content

CPANEL-43352 - using spf_installer to remove entry

Comments

9 comments

  • cPRex Jurassic Moderator
    Hey there! When I test this on my end, it takes that value as a literal string, so it adds "-ip4:1.2.3.4". Here is an example from my DNS zone after running your command: cptest.com. 14400 IN TXT "v=spf1 +a +mx +ip4:10.2.35.7 -ip4:1.2.3.4 ~all"
    This isn't the intended behavior, so I've created case CPANEL-43352 to have our developers review this. They will either fix that tool, or provide us with updated documentation. My testing did show that the command will overwite data. So if you want to remove a certain IP, just dont' include that in the command. For example, if your record looks like this: cptest.com. 14400 IN TXT "v=spf1 +a +mx +ip4:10.2.35.7 +ip4:1.2.3.4 -ipv4:4.3.2.1 ~all"
    and you want to remove the 4.3.2.1 address, just run this: /usr/local/cpanel/bin/spf_installer cptest +ip4:1.2.3.4
    0
  • 123Host
    Thanks, I am pretty surprised no one has reported this before . The problem for me now is that I can't update ALL zone files using the overwrite method as some include other entries for 3rd party mail providers e.g. Microsoft or Google . Short of just leaving the unwanted entry until this is fixed, any suggestions?
    0
  • cPRex Jurassic Moderator
    I don't have any other suggestions except manually adjusting the entries in the DNS zones, unfortunately.
    0
  • Unnamed User

    I want to delete an ip adress whats the code? what i have now is: 

     

    /usr/local/cpanel/bin/spf_installer cpuser -ip4:1.1.1.1 0 0 1

     

    But it adds the -ip4:1.1.1.1 instead of delete? im runing version 116.0.11 

    Please help i need to do in bulk

    0
  • rbairwell

    /usr/local/cpanel/bin/spf_installer can only be used to install a SPF policy: if you want to delete entries, you can either use it to regenerate a policy afresh using:

    /usr/local/cpanel/bin/spf_installer cpaneluser "" 0 1

    (run " /usr/local/cpanel/bin/spf_installer " without any parameters to get the full list of parameters/arguments - arguments are numbered so the above example has the 0="is-complete" and 1="overwrite").

    which will create a new policy only including "+a +mx +ip4:<main server ip>".

    If you need to edit the existing SPF records, this is best done via the WHM control panel by modifying the DNS zone record (in WHM: DNS Functions->DNS Zone Manager->Select zone and then "Edit" against the "TXT" record starting "v=spf1") or via Cpanel using the easier Email->Email Deliverability->(select domain)->SPF and select "Customize" or the slightly more manual way via Domains->Zone Editor->Select "Manage" against the zone-> and then "Edit" against the "TXT" record starting "v=spf1"

    0
  • Unnamed User

    I want to migrate more then 300 users. So alot of them has a modified spf record. Thats the problem that i cannot set a fresh spf. It just need to delete an entry and let the rest stay..

    0
  • rbairwell

    The only way to do this that I am aware of is doing something like https://support.cpanel.net/hc/en-us/articles/360044991473-Bulk-edits-to-your-DNS-Zones .

    In theory, the following command line entries should do what you want (where 192.168.1.0 is the IP address you want to remove):

    cp -rf /var/named{,.backup}
    find /var/named/*.db -exec perl -pi -e "s/\Qip4:192.168.1.0\E ?//g" '{}' \;
    find /var/named/*.db -mtime -1 -exec perl -pi -e 'if (/^\s+(\d{10})\s+;\s?(?i)serial/i) { my $i = $1+1; s/$1/$i/;}' '{}' \;
    /scripts/restartsrv_named

    Which will:

    1. fFrst backup the zone files
    2. Find all files ending .db in /var/named and run a Perl command against them.
    3. The Perl command uses regular expressions to find the "quoted string" [/Q.../E] "ip4:192.168.1.0" followed by an optional space [ ?] and substitute/replace [/s] it with nothing [//]
    4. The next command then finds all files ending .db in /var/named modified (mtime) within the last day (mtime 1) and then run a Perl command against them.
    5. The Perl command looks for all lines with a 10 digit code in them with the word "serial" following (which should just be the serial record line). It then increments the serial code by one and saves it.
    6. Then named is restarted.

    This will fail if the IP address is in a slightly different format (such as 192.168.001.0) or has a subnet attached to it (such as 192.168.1.0/32).

    0
  • Unnamed User

    Thank you so much! I need to delete an hostname so i can replace the ip by the hostname like this:

    find /var/named/*.db -exec perl -pi -e "s/\Q{HERE COMES HOSTNAME}\E ?//g" '{}' \;

    Thank you 1000 times!

    0
  • Unnamed User

    I want to tank you so much! it works like a charm. thanks again!

    0

Please sign in to leave a comment.