Forum Discussion

mbamusa_59409's avatar
mbamusa_59409
Icon for Nimbostratus rankNimbostratus
Jan 24, 2012

Restrict Access based on country using LTM or ASM

hi all;

 

 

could you please help me to find a way to restrict access to virtual server for some countries using irule and GEOLocation Data Base .

 

 

thank you

 

 

Mbamusa

 

9 Replies

  • Hello,

     

     

    you can find more info on how to use this on: http://devcentral.f5.com/wiki/iRules.whereis.ashx
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    mbamusa, can you work with Frank's answer or do you need additional information and/or help?
  • thank you Frank and Arie for the support , but could you please provide me an example (i.e. restrict access comes from China and Russia )

     

     

     

  • Here's a positive example:

    
    when CLIENT_ACCEPTED {
         Get the country client IP 
        switch [whereis [IP::client_addr] country] {
            US -
            CA -
            MX {
                set allowed 1
            }
            default { set allowed 0 }
        }
    }
    when HTTP_REQUEST {
        if {$allowed == 0}{
            HTTP::respond 403 content {Blocked!}
        }
    }

    And here's a negative example:

    
    when CLIENT_ACCEPTED {
         Get the country client IP 
        switch [whereis [IP::client_addr] country] {
            "CN" -
            "RU" {
                set allowed 0
            }
            default { set allowed 1 }
        }
    }
    when HTTP_REQUEST {
        if {$allowed == 0}{
            HTTP::respond 403 content {Blocked!}
        }
    }

    If you don't need to send an HTTP response you can use reject to reset the TCP connection:

    
    when CLIENT_ACCEPTED {
         Get the country client IP 
        switch [whereis [IP::client_addr] country] {
            "CN" -
            "RU" {
                 Reset the TCP connection
                reject
            }
        }
    }

    Aaron
  • can you try this?

    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when CLIENT_ACCEPTED {
            switch [whereis [IP::client_addr] country] {
                    CN -
                    RU { drop }
                    default {
                            do something else
                    }
            }
    }
    }
    
  • oops! my page was not updated. Aaron's one is nicer. please follow his. :-)
  • Thank You All for your kind Support , i'll Try the IRule and I'll get back to you with the result .

     

     

    mbamusa
  • Dear All;

     

     

    i tried hoolio's Irule and it's working perfect thank you all for your kind support .

     

     

    mbamusa
  • I think iRule take a lots of resources, you should try the ASM geolocation feature before u make up your mind on iRule. The detailed write is here.

     

    Cheers