Forum Discussion

Lucas_Kaczmarsk's avatar
Lucas_Kaczmarsk
Icon for Nimbostratus rankNimbostratus
Mar 06, 2015

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

 

3 Replies

  • 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
            }
        }
    }