Forum Discussion
iRule for host rewriting between nodes
- Feb 12, 2025
Finally it works ok with the Data group + iRule solution.
Thanks to all of you!
Hi Martin,
You can try add logging statements to your iRule to capture the selected server and the rewritten Host header. This will help you verify that the iRule is executing as expected.
Adding logging can help debug the issue:
when LB_SELECTED {
log local0. "Selected server: [LB::server addr], Host: [HTTP::host]"
switch -glob [string tolower [HTTP::host]] {
"service1.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service1.ocp.site1.com"
HTTP::header replace Host "service1.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service1.ocp.site2.com"
HTTP::header replace Host "service1.ocp.site2.com"
}
}
"service2.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service2.ocp.site1.com"
HTTP::header replace Host "service2.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service2.ocp.site2.com"
HTTP::header replace Host "service2.ocp.site2.com"
}
}
"service3.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service3.ocp.site1.com"
HTTP::header replace Host "service3.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service3.ocp.site2.com"
HTTP::header replace Host "service3.ocp.site2.com"
}
}
"service4.dns.com" {
if { [LB::server addr] eq "192.168.50.100" } {
log local0. "Rewriting Host to service4.ocp.site1.com"
HTTP::header replace Host "service4.ocp.site1.com"
} elseif { [LB::server addr] eq "192.168.50.101" } {
log local0. "Rewriting Host to service4.ocp.site2.com"
HTTP::header replace Host "service4.ocp.site2.com"
}
}
}
}
This will log the selected server and the host header, helping you verify if the conditions are being met and the headers are being rewritten correctly.
Use a tool like curl or a web browser to generate traffic to your virtual server. For example:
curl -H "Host: service1.dns.com" http://192.168.50.100
curl -H "Host: service2.dns.com" http://192.168.50.100
curl -H "Host: service3.dns.com" http://192.168.50.100
curl -H "Host: service4.dns.com" http://192.168.50.100
curl -H "Host: service1.dns.com" http://192.168.50.101
curl -H "Host: service2.dns.com" http://192.168.50.101
curl -H "Host: service3.dns.com" http://192.168.50.101
curl -H "Host: service4.dns.com" http://192.168.50.101
When you run the command curl -H "Host: service1.dns.com" http://192.168.1.100, you are making an HTTP request to the server at 192.168.50.100 and setting the Host header to service1.dns.com. This simulates a request as if it were coming from a client trying to access service1.dns.com, allowing you to test how your iRule handles this specific host.
Check Logs:
Review the logs on your F5 load balancer to verify that the iRule is executing correctly. Look for the log entries you added to confirm that the Host header is being rewritten as expected.
Ensure that the applications on OpenShift are receiving the correct Host headers and responding appropriately. Check for any 404 errors or other issues.
Monitor the traffic and logs to ensure the iRule continues to function correctly. Make any necessary adjustments based on your observations.
Use tools like grep to filter and view specific log entries. For example:
grep "Selected server" /var/log/ltm
grep "Rewriting Host" /var/log/ltm
HTH
Best Regards
F5 Design Engineer
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com