Retrieve location details from user IP address using geolocation database
-
Insert an HTTP header with user location details (such as country, city information) when sending the client request to the back-end server.
-
Add country name in the HTML page response for an invalid user.
Getting user location details using geolocation functions
-
User sends a client request from a particular geographic location.
-
The NetScaler appliance looks for the user IP address from the client request and retrieves the geo location details. The details include continent, country, region, city, ISP, organization, or custom details from a geolocation database.
-
Once the location details are retrieved, the appliance uses either a responder policy or a rewrite policy to evaluate the request.
-
In a rewrite policy, the appliance adds a header with the geo location details and sends it to the back-end server. For example, insert a custom HTTP header with country information.
-
In a responder policy, the appliance evaluates the HTTP request and based on policy evaluation, allows access to the users or redirects the user to an error page. It states the region from where they are accessing the application does not have access.
Setting up geolocation database
Geolocation functions
| Geolocation function | Example |
|---|---|
| CLIENT.IP.SRC.LOCATION | Asia.In.Karnataka.Bangalore |
| CLIENT.IP.SRC.LOCATION.GET (1).LOCATION_LONG | India |
| CLIENT.IP.SRC.LOCATION(3) | Asia.In.Karnataka |
| CLIENT.IP.SRC.LAT_LONG | 12,77 |
| CLIENT.IPV6.SRC.LOCATION | North America.US.California.Santa Clara.Verizon.Citrix |
| CLIENT.IPV6.SRC.LOCATION(3) | North America.US.California |
| CLIENT.IPV6.SRC.LOCATION.GET(1).LOCATION_LONG | United States |
| CLIENT.IPV6.SRC.LOCATION.GET(3) | California |
| CLIENT.IPV6.SRC.LAT_LONG | 36, -119 |
Configuring geolocation functions
Enable load balancing, responder, rewrite features
enable ns feature loadbalancing rewrite responder
Use case 1: Configuring geolocation function for redirecting invalid users outside geo location
-
Add responder action
-
Add responder policy
-
Bind responder policy to load balancing server
Add responder action
add responder action <name> <type> (<target> | <htmlpage>) [-comment <string>] [-responseStatusCode <positive_integer>][-reasonPhrase <string>]
add responder action responder_act respondwith "HTTP.REQ.VERSION + \" 304 Requested Page not allowed in your country - \" + CLIENT.IP.SRC.LOCATION.GET (1).LOCATION_LONG + \"\r\n\""
Add audit log message action
newnslog formats. Audit-message actions use expressions to specify the format of the audit messages. To create an audit message action by using the command line interface
add audit messageaction <name> <logLevel> <stringBuilderExpr> [-logtoNewnslog (YES|NO)]
add audit messageaction msg1 DEBUG "\"Request Location: \"+CLIENT.IP.SRC.LOCATION"
Add responder policy
add responder policy <name> <rule> <action> [<undefAction>] [-comment <string>] [-logAction <string>] [-appflowAction <string>]
add responder policy responder_pol CLIENT.IP.SRC.MATCHES_LOCATION("Asia.India.*.*.*.*") responder_act -logaction msg1
Bind responder policy to load balancing server
bind lb vserver <vserver name> -policyName < policy_name > -priority <> -type <L7InlineREQUEST | L4Inline-REQUEST>
bind lb vserver http_vserver -policyName responder_pol -priority 100 -type REQUEST
Use case 2: Configuring geolocation function for inserting new HTTP header with location details for back-end to respond
-
Add rewrite action
-
Add rewrite policy
-
Bind rewrite policy to load balancing
Add rewrite action
add rewrite action <name> <type> <target> [<stringBuilderExpr>] [-search <expression>] [-refineSearch <string>][-comment <string>]
add rewrite action rewrite_act insert_http_header "User_location" CLIENT.IP.SRC.LOCATION
Add rewrite policy
add rewrite policy <name> <rule> <action> [<undefAction>] [-comment <string>] [-logAction <string>]
add rewrite policy rewrite_pol true rewrite_act -logaction log_act
Bind rewrite policy to load balancing
bind lb vserver <vserver name> -policyName < policy_name > -priority <> -type <L7InlineREQUEST | L4Inline-REQUEST>
bind lb vserver http_vserver -policyName rewrite_pol -priority 100 -type REQUEST
Syslog support for logging geolocation details (optional)
Output for user geolocation details
newnslog action if you try to access an application from the Bangalore location and if the appliance uses the geolocation function, "CLIENT.IP.SRC.LOCATION'.
Asia.India.Karnataka.Banglore
07/23/2018:19:03:54 GMT Debug 0-PPE-0 : default REWRITE Message 22 0 : "Request Location: asia.in.karnataka.bangalore.*.*"
07/23/2018:19:23:55 GMT Debug 0-PPE-0 : default RESPONDER Message 32 0
Done