7

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

alexus
  • 12,342
  • 27
  • 115
  • 173

2 Answers2

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

sub vcl_recv {
    if (client.ip ~ unwanted) {
        error 410;
    }
...
}
alexus
  • 12,342
  • 27
  • 115
  • 173
  • 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 05:37
  • Same her, trying to figure it out. Will report back – Eirik H Oct 29 '15 at 09: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
2

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"));
    }
}
Totor
  • 2,876
  • 3
  • 22
  • 31