irule problem - allow only selected IPs

Hello Guys,

I’m new to irules so please excuse my basic question. I’m trying to allow traffic only to the two IP addresses, but the irule below only matches the first one. Any idea why?

when HTTP_REQUEST { if { not [IP::addr [IP::remote_addr] equals 1.1.1.1] or [IP::addr [IP::remote_addr] equals 2.2.2.2]} { reject } }

Thanks, Lucas

Try this. You needed to put

()

around the IP address checks, otherwise it was checking not 1.1.1.1 or IS 2.2.2.2

when HTTP_REQUEST { 
    if { not ([IP::addr [IP::remote_addr] equals 1.1.1.1] || [IP::addr [IP::remote_addr] equals 2.2.2.2])} { 
        reject 
    }
}

Or you could try with a

switch

statement instead, like this:

when HTTP_REQUEST {
    switch [IP::addr [IP::remote_addr] mask 255.255.255.255] {
        "1.1.1.1" -
        "2.2.2.2" {
             Do nothing
        }
        default {
            reject
        }
    }
}

Thank you so much! It’s all working fine now :slight_smile: