How does one block either IP address of network range inside of Varnish's VCL file?

up vote 7 down vote accepted
acl unwanted {
    "69.60.116.0"/24;
    "69.90.119.207";
}

sub vcl_recv {
    if (client.ip ~ unwanted) {
        error 410;
    }
...
}
  • 1
    im using varnish version 4 and i got error this one when reloading vcl config: Message from VCC-compiler: Expected an action, 'if', '{' or '}' ('input' Line 40 Pos 1) error 410; #####----- – risnandar Jul 28 '15 at 5:37
  • Same her, trying to figure it out. Will report back – Eirik H Oct 29 '15 at 9:36
  • @risnandar this is version 3 syntax. Since version 4, there is a new one, see my answer. – Totor Jan 23 '17 at 17:06

Since Varnish 4, the syntax has changed!

Instead of:

error 403;

you need to use:

return(synth(403, "Access denied"));

Using alexus' example:

acl unwanted {
    "69.60.116.0"/24;
    "69.90.119.207";
}

sub vcl_recv {
    if (client.ip ~ unwanted) {
        return(synth(403, "Access denied"));
    }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.