Forum Discussion

yuanqiang_22112's avatar
yuanqiang_22112
Icon for Nimbostratus rankNimbostratus
Sep 28, 2018

Domain name access only

Hi LTM version 11.5.1, Please provide irules for domain name access application only .

Thankyou .
  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    It is not clear what your requirement is.

     

  • Do you mean an iRule that ensure that the client cannot access the application via the IP address? If so, that is very simple - just check the HTTP Host header.

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host] ] != "" } {
            reset
        }
    }
    
  • @Pete White:

    Try your irules, not work ; Modify the iruels can work :
      when HTTP_REQUEST {
    if { [string tolower [HTTP::host] ] != "www.f5.com" } {
        drop
    

    log [HTTP::host] }

    }

    Which string can expression all domain name , not work , you know ?

  • Try that

    when HTTP_REQUEST {
        if { !([string tolower [HTTP::host] ] ends_with "company.com") } {
            reset
        }
    }
    
  • OK. I meant that you should replace with the FQDN that your application is using.

    I guess you are asking for an iRule that stops any requests with an IP address as the Host header.

    when HTTP_REQUEST {
        if {[regexp {^(?:(\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))(?:\.((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))){3}$} [HTTP::host]]} {
            reset
        }
    } 
    

    Note that regex is not very performant but this will check the host header against a regex for an IP address. You could consider using string match or the suggestion above by Stanislav if you know the domain that you want to use.