What you'll learn
- Explain how iRule events such as CLIENT_ACCEPTED and HTTP_REQUEST trigger commands to run on a BIG-IP virtual server
- Use the F5 iRules documentation to look up commands, events, and per-version changes before an upgrade
- Attach an iRule to a virtual server's resources and verify it is applied to live traffic
- Configure iRule logging and review the entries with tail on /var/log/ltm to support troubleshooting
- Write an iRule that steers traffic with an HTTP redirect using client IP and other values in square brackets
- Troubleshoot iRule errors by distinguishing Tcl errors, deprecated syntax warnings, and hidden copy-paste characters
Free 47-minute video lesson with a full transcript and knowledge checks. No account needed to watch.
Introduction
So you want a tool that you can use to do things like redirect requests, manipulate data, or even send specific inbound connections to a specific member server in a pool? You've come to the right place because iRules can do all of those things and much, much more. We're going to explore iRules and some of their more common uses. We'll create some iRules and see them in action and discuss the importance of being able to read an iRule and know what its purpose is.
iRule Events and Commands
When it comes to iRules, they have their own set of rules as far as what triggers them, the actions they take, and their formatting. Let's jump in and talk about all of these iRules rules.
Knowledge Check
iRules are __________ driven. (What word best fills in the blank?)
iRule Commands
Now that we understand the makeup of iRules and that they are event driven, it's time to take a look at our command options which are many.
---> F5 iRule command documentation
Knowledge Check
There is a very simple list of iRule commands, about 20 commands in all.
iRule Logging
One of the features we can do with iRules is to log data. We can decide when a specific event occurs that we should log specific data. This can be very helpful for not only record of the event, but for troubleshooting.
Knowledge Check
To which file location does the following iRule send its log data? CMD: log local0.notice "Host: [HTTP::host], Client IP: [IP::client_addr]"
iRule Errors
What? iRules can have errors? Absolutely, since iRule is basically a script it can definitely have errors occur. That being said, how do we troubleshoot errors and where are these errors logged to?
Knowledge Check
To where are iRule errors logged?
iRule Traffic Steering
Another popular use of iRules is to "steer" traffic. We may want to redirect traffic to another location, or send traffic from a specific source to a certain pool member. Let's take a look at how we can do this.
Knowledge Check
If we want to send an incoming web request to a different location, which of the following EVENTS would we use to trigger the iRule?
Validation
It's time to answer a few review questions dealing with iRules. After the questions will be a solution video where I'll walk through the questions and explain the answers.
NOTE: If you plan to take the F5 LTM Specialist exam you will want to spend some time on the F5 DevCentral site looking at various iRules and learning what they do. This will allow you to become familiar with many of the more common events and commands used in iRules.
Question 1:
Knowledge Check
Your company is rolling out an updated web application at a new URL. The old URL is www.nuggetlabz.net and the new URL is www.nuggetlabz.com . Which of the following iRules will allow clients connecting to the old URL to still be able to access the new updated web application? Refer to the images below and choose the answer that correlates to the correct image.
A.
when HTTP_REQUEST {
if {[HTTP::host] equals "www.nuggetlabz.com" }
{
HTTP::redirect "http://www.nuggetlabz.net" }
}B.
when HTTP_DATA {
if {[HTTP::host] equals "www.nuggetlabz.*" }
{
HTTP::redirect "http://www.nuggetlabz.net" }
}C.
when HTTP_REQUEST {
if {[HTTP::host] equals "www.nuggetlabz.*" }
{
HTTP::redirect "http://www.nuggetlabz.com" }
}D.
when HTTP_REQUEST {
if {[HTTP::host] equals "www.nuggetlabz.net" }
{
HTTP::redirect "http://www.nuggetlabz.com" }
}Question 2:
Knowledge Check
Your company has recently moved its web application to a new location and to ensure users can still access it at its old location you've setup a redirect on the application servers. You've been tasked with setting up an iRule that will log all of the redirects so that you can ensure it's working properly. Which of the following iRules will do this? Refer to the images below and choose the answer that correlates to the correct image.
A.
when HTTP_RESPONSE {
if { [HTTP::is_3xx] }
{
log local0. "redirecting client ip address [IP::addr [IP::remote_addr]]" }
}B.
when HTTP_REQUEST {
if { [HTTP::is_301] }
{
log local0. "redirecting client ip address [IP::addr [IP::remote_addr]]"}
}C.
when HTTP_REQUEST {
if { [HTTP::is_redirect] }
{
log local0. "redirecting client ip address [IP::addr [IP::remote_addr]]" }
}D.
when HTTP_RESPONSE {
if { [HTTP::is_redirect] }
{
log local0. "redirecting client ip address [IP::addr [IP::remote_addr]]"}
}Question 3:
Knowledge Check
When an error occurs within an iRule in production, what will the end result of the connection be?
Question 4:
Knowledge Check
If your iRule isn't working as expected, what would you look for in the /var/log/ltm log file that would indicate an iRule error?
Validation question solution video:
Knowledge Check
Have you used iRules on a Big-IP device?
This interactive assessment is available in the full learning experience.
View Transcript
iRule Events and Commands
0:00Let's talk about eye rules. So we're starting off here with some lower level eye rule discussion. Just as a quick refresher, in case you need it, that eye rules are an event driven language. And what does that mean? Well, it means an event triggers a command or triggers something to happen. So what does an event? Well, it could be things like when a connection is established from a client to a server, or it could be the response from the server to the clients.
0:33Or during this here, we have the F5 here, or our big IP. Well, when the big IP chooses where to load balance something to, that's an event, there's lots of different events. And actually, when this client connects in, remember, we're going to have that TCP three way handshake, most likely, that's going to terminate here at the big IPs external, or the IP of the virtual server. And that connection, when it's established, that's an event.
1:06So whenever there's an event, then we can trigger some commands to run. And that's how we do that. So it's really like a win. An event is win. Win this happens. Then we want to do this. And that's pretty much how I rules work. So let's take a look at an example of an I rule, or two. All right, here we go. Here's a couple of examples. So when here we have the client accepted, so that is the client accepted the connection.
1:42And here we're actually doing an if in here. So if the IP of the client address equals 172.16101.5, then drop that connection. Oh, that's pretty interesting. So here's another one. Win the HTTP request. So here we're looking at HTTP data. So really, we should be using our HTTP profile to give us access to layer seven data, where that HTTP request will reside so we can read what's in it.
2:13So it says here, win the HTTP request, it wants you to go ahead and log local zero. That's our var log LTM. It wants you to log host. And then what this is, is a variable. It's information in there actually. So it's pulling out of the HTTP request, the host. And it's going to grab the client IP address there. So basically every time there's an HTTP request, it's going to log the host and client IP address.
2:43So this is what it is. So we have our event here. And this one is-- there we go, let's make-- there we go. Our event is client accepted. This one is HTTP request. And then we're going to have a command after that. You can do an if statement or if else. Or you could simply run a command to do something like log something for you. So there you go. Now, I do want to talk about something else here. And this is iRulePriority. And that's because our iRuless are, well, in priority.
3:14If you have a list of rules here, well, how does this work? Which one goes first? Comes down to priority. And you can assign a priority value to an iRule. And if you do not assign one, the default priority value is equal to 500. And the way this works, though, is the lower the number, the higher that priority. So 0 through, let's say, 500.
3:45So if I have a list here and I have some at 0 and maybe 1 at 10 and 20 and 100, well, the priority is from 0 to higher numbers. Now, if you do not assign the value, it uses the default value of 500. And let's say in your web UI here, our config utility, everything set to 500. At that point, it is top down. So it will just go top down from what you see in your view. And it'll go through until it makes a match. So that's the basics of events and commands and priorities with iRoles.
4:19Now, what do you say we jump in in the next digit and start taking a look at iRole commands? Because there are a few of them, as you will find out. So I'll see you there shortly. [BLANK_AUDIO]
iRule Commands
0:00All right, as I said, we're going to now take a look at some I rule commands because we've talked about events And we're gonna look at events as well. We're gonna look at both of them So here we are. We are at the F5 documentation. I rules home. This is where we come for our I rule references And I will provide this link here in the nugget. So here we go Wow, let's get started Because you'll see there's lots of commands now. Let's take a look over here at the left See if I can't here zoom in a little bit now here on the left I rules home. So first of all We have big IP commands and events by version. So let's click on that. Let's take a look at this So what we have is for each version you're gonna be able to go in and look at what changes were made for that version Which is good because as you upgrade versions throughout the life cycle of your big IP You're gonna need to understand if you're using I rules What I rules have changed. So let's say let's take a look at the 17 1 0 is the latest there And we'll see there's just three of them here dealing with the ASM module So we have this new command. It looks like is authenticated login status and username So we can actually use those this username is request username from a login attempt through a login session So that we can maybe log that or do something it would if if we need to but you
1:19'll see here This is a couple of commands and these are just the changes though. Keep that in mind. These are only the changes so let's go back here and Let's go back over to our menu on the left here Now here's what I want you to see all of these will click on global contain a command list and we're gonna scroll all the way Yeah, lots of commands, right and they're associated events. So these events can be used to trigger these commands so here events these are global commands and events and So server initialization We have persist down name resolved a lot of them here, right?
2:00Okay, so let's go look at some commands then so these are some commands up here . So as you can see there's a lot of them I know a lot right So as we keep going there you go. So those are our global But we also if we scroll down here, we see this keeps going. Yeah a whole lot down here. There we go all the way down to At the bottom our X and now So when we start working with maybe the TMM we go take a look at the TMM. Well, there's some TMM commands There are no events associated with that, but you can use other events to call or trigger the command to run Maybe we've got triple a for authentication and Authorization to access you got here's some access commands. There's APM commands ASM Let's see. There's just a whole bunch really so when it comes to these I rules That's when we're looking to do something with the incoming data We're looking to manipulate the data or steer it to a specific Destination maybe do a redirection or send it to a specific pool member We can again manipulate the data in it. We can change information Here's some HTTP This is something you should definitely look at if you plan on taking the
3:17certification for the LTM specialist You will be tested on The I-rolls and you're gonna need to take a look at an I-roll and figure out what it's doing. So HTTP It's good to know because we're gonna actually look at some of these especially when it comes to Response and request because here at the request for example if I click on this it's gonna take me in here And I can see this HTTP request we return to the raw HTTP request headers as a string So that you can actually access that information in the HTTP header and the request is gonna contain the information being requested Such as URI this being requested the URL the target name or watch it not The destination address all that stuff. That's your HTTP request But then also we have a HTTP response and the response is gonna be return traffic From the server and that's gonna contain information such as if there's red irection is going on it's gonna be in the response You'll see that coming up. So again as we go back. There's a whole lot of these So again if you plan on taking the certification exam I highly recommend you go over to Dev Central and you start looking at I-roll just to search for I-roll That's all you got to do and you will find tons of articles and
4:34People working on I-roll so that you can get familiar with many of the most common commands So that you'll be able to decipher what I-rolls are used for okay? That's very helpful if you're gonna take this certification exam now if you're not this is where you come and this is your repository for looking for information and and to be honest we're probably just gonna Google for I-rolls but this is the Indol BL to your resource for these commands so you can always go and take a look at a command So let's say you you see one that says HTTP header Well, what does that mean so you click on here and it's gonna tell you what it means?
5:13Okay, so what it's used for the syntax that you can use it for some additional information down here That's gonna help you with your I-roll so this is such an important place When it comes to your I-rolls and the commands and the events associated with them So this should be bookmarked in your studies when it comes to your LTM specialist command and really if you're an LTM administrator or big IP administrator This you need to be bookmarked somewhere This is what you're gonna be using when it comes to your I-rolls it's gonna be a great resource for you And now you know where it's at and the link will be right below the video Or you can see it maybe up here in the video. We're not quite sure how this is gonna turn out as far as zooming So there you go. That is your I-roll event and command resources straight from F5 in the next night. We're gonna talk about I-roll logging. So see you there shortly [BLANK_AUDIO]
iRule Logging
0:00Alright, here we are in our iRULES home once again as we saw in our last nugget . And now we're taking a look at iRULOGGING. Okay, and this is when we use a command to log information as part of an iRUL so that an event occurs and as a result of that event we trigger a command to log some data. And this is used very frequently, like a lot. And especially the troubleshoot. Because if I'm working on something and I need to gain access to specific information, let's say I'm trying to find out where something is load balanced to.
0:35Well what I can do is actually use an iRUL to identify my test box coming in and then log where it's been load balanced to. So I can use it to troubleshoot. There's lots of things. We use them a lot for troubleshooting, especially with the login command. Okay. So that being said, let's go over to global. There we go. And log command. So let's scroll on down here and there it is. Log right here. Let me zoom in. Right there is our log command that says generate and logged a message to the syslogging utility.
1:07Awesome. So let's go ahead and click on that. Let's find out some information about it. Alright, super. So this generates and logs specified messages to the syslogging utility which we just saw. Alright. Let's take a look at the syntax log or you could simply put a message in there. You can also use log with the no name option. The no name option. What this does, it prevents the logging of the iRUL name and the event that prefix the actual message.
1:37Alright, it just abbreviates your log entry. We can also set the facility level in this facilities where it's going to log to member our local zero is our var log LTM. Let me have our logging level, remember that's zero through seven or we can use the words and we can then add a message after that. Okay. But if we want to log to a remote host, let's say to a, I don't know, syslog server, then you can put in here the remote IP address and remote port where you want to log to.
2:09So it'll send it to that destination instead of your local facility. Okay. So if we go down here and look at some examples. Here we go. So as simple as it gets log local zero, you know, this message and these are variable to have dollar signs in front of them. There's a system variables that can be used. Alright. So let's see. Here you go. Here's triggering it when client accepted. So when a client accession is accepted, what we can do is log and this is logging to, that's right, a remote syslog server.
2:44We're also providing information here. Alright. We've got our local zero and our info level and we say here client connected IP and then we're going to have the IP of the client address. So those are a couple of examples. They're dealing with the log. So now that we see what this looks like, let's go ahead and see it in action. Alright. Here we go. Let's go over here. We're on our big IP and what we're going to do is go over here to local traffic , go down to our iRULES and I've got one right here called Bob logging.
3:22Let's open this up and see what this looks like. Alright. It says when HTTP requests, so a web request, whenever a web request comes in, it's going to log local zero. Alright. That is our var log LTM. I'm going to log it as a notice level. It's going to provide host, the HTTP host and then the client IP and here the client IP address. Now, it's very important we understand the formatting use here. So you have an event and that event triggers a command.
3:53The command needs to be wrapped with, that's right, these curly brackets and then down here whenever we're trying to pull information from like here our HTTP headers, those need to be hard bracketed. Okay. And you'll see it over here as well from IP, we're pulling that information in. So really this is just going to log some information for us. So let's turn this on. So this is my Bob logging. Let's go over here to virtual servers. Let's go over here to my HTTP app one, let that load up, go over to our resources and under our iRULES right here we're going to add scroll over here to manage.
4:28There we go. We're going to add Bob logging because an iRUL not attached to a virtual server is simply a stump on a log. Finished. There you go. Now this is actually going to be used. Alright now let's go ahead and see this in action. So what I'm going to do is let's see the spring up our terminal and actually we 're going to go jump to our windows box first. There we go, windows box. So I'm going to open this up and I'm going to query. There we go. Let's do a incognito window just in case we have some cached information.
5:00There we go. Alright. So that's that. And let's bring this up. And let's do var log LTM, tail it. And there we go. Right here. There is our information. So this is big IP one. If I buy up notice and here's the rule that it hit says, it's our Bob blogging rule HTTP request. There's the host. 1.2.16.101.11. It's a big IP and the client IP 1.6.2.16.101.5.
5:30So now we see that logging in action. We're at IDR and cool. Alright. Now here's a question. Why would you ever want to use this? Well, we might use this to log specific traffic of activity that we want to document in the logs. Maybe we want to document when certain IP addresses or networks communicate and we might want to see that. We might want to graph that. So we send it off to a syslog server from here. And on that syslog server, we may have some applications that can use that sys log information to graph and show where things are coming from, so on and so forth.
6:03But then again, we could use it for lots of things logging, especially with troubleshooting. If I'm having problems with something, I can come in here and I can go back to my, let's see over here to the big IP and come down to the eye rules and say, maybe I want you to instead of log this information, I want you to log additional information, right? I can pull lots of stuff. And it's not just HTTP requests. I can do HTTP connect or HTTP response or lots of different things or well, we saw all the commands we can use.
6:33So when something happens, we can actually log all this information. And that way it'll help us troubleshoot. See what's going on underneath the hood, if you will, of our system house processing that data. Now do keep in mind that when we're doing this, if we're sending a bunch of stuff like this, every HP connection to the logs, that's going to create a lot of log data. And our logs are going to overwrite quite frequently. So this is not something I would do in production necessarily, unless I had a really good reason, because every time there's an HTTP request, it's going to log where it's coming from and where it's going to here.
7:11And that's just a whole lot. And actually, let's take a look at creating this because this I just showed it to you, right? So what you can do is we're going to win a speed underscore and you'll see it fills in. It shows you all your events that you can use at this point. So it could be response, request, send, release data request. And so we'll just go with our request local, like we did. And we do our open curly bracket and then tab that out. And you don't have to. It just makes it easier to remember. I say I want to do log, right? So you hit L.
7:41Well, what do you want to do? These are all your commands that start with L up here. So I'm wanting to do listen, or we're just going to do log. And there I want to do, there we go, local and it says, well, where to local address or let's just local zero and you put your period in there. And then what level are you going to do? We put our notice, yep, in for notice, there you go. And then we're going to put our message. So here, if I want to do, let's say host and I put the colon because that's just the word host shows up there.
8:12And then what do I want to follow that? Well, that's where my hard brackets are going, not curly brackets, but your straight brackets. And I want HTTP data. So here, put that now, what do I want? It gives us all this very nice IDE or integrated developers environment kind of in this to help us along with our options because there are a ton of options. So what we could do is what do we want here? The host, do we want the host, how about IP address? Is IP address in here or address is probably in here?
8:43And let's see, see, to say we'll follow up header host, host, we looked at method, pass through pass payload query redirect. And I don't see any kind of address, which is fine. But you could do the something like the URI, we could actually find out what you are either going to try to access. So here, we can do that. So actually here, we would probably change this to URI because it's going to kind of match that you could do that. And then put our comma, what we want to do, our client and IP and these are just words at this point.
9:13But then once I bracket, I'm putting something important. I want to pull information from the IP header. So I could say IP and there's client address. So I could do client address that we did. We could do address is better to do client address because the address you're not sure if you're going to get like a destination or source. Client address is very specific. I could do remote address, server address. Let me see what I'm going with that there. So let's actually go with let's just leave client address. But then what if we wanted to know the port number? Well, then we could put comma port colon space and again, those are just words here.
9:48Now if we go to TCP, that's where our ports are going to be because it's the TCP layer. Let's see if we go down here and find. Let's see, there's payload, push, receive, scale and there's unused port. Let's see, server port. There's server port you could put in there is there and that's probably that's going to be like destination port. That's what we'd be looking for is our client port. There probably is. Yep, there's our client port. So really we'd be looking probably at our server port. We want to know where it's going to on the port.
10:20So at that point we'd close that. All right, and we close this and then we have to wrap up with a curly bracket to finish it out and it just like that nice little formatting. There you go. Or if you're going to do more than one thing, we could then close that. But then what we could do is actually we'd probably do this. Go back here. I'm going to close that curly bracket and I'm going to do an open bracket, enter and then I could run another command if I wanted to. So I could do lots of different.
10:50I mean just I don't know. The sky is the limit when it comes to these commands because there's so many of them. But you could put your next command down here and then we'd come down here and go ahead and close that out. So then you could run and you could nest all these commands and you can do if ill statements, you know, lots of different things as you get in here and start playing with these. And then I think too, you can hover over this like HTTP request and it's going to give you some information you can look at. So oh, well look, there's some examples. HP redirect. Where's this being sent to?
11:20You know, all these wonderful things. And actually we're going to deal with working with steering, which is where we steer our traffic to a new destination or somewhere else. And we're going to look at that here upcoming shortly. So that wraps up our I rule logging. We're going to actually look at I rule errors because believe it or not, you're going to see a bunch of errors when you go playing with these things. They can be a serious pain in the rear at times, but use your documentation, do some Googling and research and look for the errors.
11:50Those are going to be key. All right. So there we go. That wraps this up. I'll see you in the next nugget. [BLANK_AUDIO]
iRule Errors
0:00It's time to talk about errors. I-rule errors to be more specific. And when it comes to I-rule errors, well, guess what? You will encounter them if you work with I-rules. So that's when you have an I-rule and you have the correct nomenclature and such in there, your events and commands, but when it's being processed, generates an error. All right, and these are known as TCL errors, or tickle errors, because tickle, which is tool command language, is the language that I-rules use that you see when we're creating I-rules, right?
0:33Those are called the tickle language, or TCL. Now, these errors are invaluable to troubleshooting your I-rules when you're having problems with them. Now, these are logged to our local zero, which is var log LTM. Let's take a look real quick here. So this is pretty much what you're gonna see. Something like this, and you're gonna have a reason. It could be that you can't read something, or the variable doesn't exist. It could be lots of different things.
1:03And again, they're located in the var log LTM file. I'll provide a link to this article here below the video. Now, I do wanna point out that if an error occurs within an I-row while it's being processed, the connection is going to most likely be reset. So that user's connection will be reset, and there you go. That's kind of what's gonna happen when you have that, and that'll be an indicator that you have a problem with an I-row. Use your descriptions, impact, and recommended actions.
1:34I recommend an action to figure out what's going on. How about that? (laughs) Pretty straightforward. All right, let's go in here. I was able to generate some errors. It's not that hard. So what we're gonna do is, I wanna show you real quick something real quick. Let's do a LS-L. I'm not gonna do that. We'll do var log LTM. I would just var log really. Either our log files. I wanna show you this because what happens with these, where's my var log LTM, where's my LTM?
2:04There, there, LTM's. Okay, so your most current logs are kept here in LTM, but once they're overwritten, once they get to a certain size, they're shipped off to LTM.1. And down to .2, but once you get down to .2, they're being zipped, okay, compressed. So what I'm gonna look at is LTM.1 because I don't have any errors in my LTM most recent log, but I do in my LTM.1 log. And it happens with all these. That's the way logging works in Linux, okay?
2:34So let's go ahead and do this. Let's enter, let's clear the screen here. Let's see the App Arrow a couple times, and there it is. What I'm gonna look at, what I'm doing is, I'm gonna, I'm reading the var log LTM.1 file, and I'm searching for TCL, but hit enter. These are TCL errors that we see here. So if we look at that, we get some information, like a timestamp where it's happening, the error, you get an ID number here, and then we see TCL error, and it is in the Bob validation I rule, all right?
3:07And it says that the server connected, this is bad IP network address format in line one. And this is what the errors look like, and this is where they are located. So it's very important for you to remember, we're looking for tickle errors, TCL errors, and these are associated with our I-RULs, and they are maintained in, that's right, var log LTM. It's very important we remember this. This is invaluable to troubleshooting our I-RULs when we're having problems with them. So that's how we can go ahead and look for I-RUL errors or tickle errors within the big IIP.
3:44Next up, we're gonna create some I-RULs and work with traffic steering. That means we're going to manipulate traffic flow with I-RULs. So I'll see you there shortly. [BLANK_AUDIO]
iRule Traffic Steering
0:00It's time to work on traffic steering or traffic manipulation with iRULES. Now I've got a couple of iRULES here we're gonna look at. We've got two of them in particular. One is Bob redirect. There is Bob redirect URI. Now the first one, well actually let's just go ahead and look at them okay. And here's what we're gonna do. I'm going to click in here. This is the, let me zoom in just a little bit, there you go. This is the iRUL. Obviously, now I'm gonna pause the video here.
0:31Actually I just encourage you to pause the video here and figure out what this iRUL is supposed to do okay. And so go ahead and pause this and take a look and when you're ready go ahead and resume. Alright I'm guessing you figured it out hopefully. Alright let's talk about this. So this starts off with the event when an HTTP request is received okay. Again it's looking at if the IP address is equals 172.16.101.5.
1:06Oh what is that? What's percent one? Think back to your partitions remember our administrative partitions? That tells it that this IP address belongs to the partition one. Without that you might run into errors or if you have IPs and different partitions you will want to define the partition there. Keep that in mind. So what this is, this is just text here. It says if this IP address and this IP address is actually going to take this information is what we're saying.
1:36If the client IP address equals 172.16.101.5 which is my Windows test box then go ahead and log a notice log local zero that's our var log LTM. Log that notice and use host it's gonna give me my HTTP host which is gonna be the big IPs IP address. On IP IP address of the client 172.16.101.5 and redirected. So basically it's gonna say hey I saw an HTTP request from 172.16.101.5 and I redirected it and that's what we're telling it to do here.
2:10Not redirected but we're saying just log that it was redirected. So basically it mats and it's processing the rule. Now the next we're defining a pool. So use a keyword pool and define the pool that I want it to redirect to then I actually defined the member of the pool that I want to redirect to which is 1011.03 on port 80 and now pay special attention. We're looking at these brackets. They're very important. See this gets wrapped right in here.
2:41That's the one command. This is the next command of brackets. And this is the next command. And all these commands are wrapped with this bracket and this bracket. And then whenever we're pulling IP address information or any information from the big IP like the IP client address we're going to have those squared brackets. You see we're saying here, same here. We're pulling those in squared brackets. Alright so that's what that is supposed to do.
3:14What do you say we tested out shall we? So this is the Bob redirect iRule. So let's go to virtual servers. Let's go to our HTTP app. One virtual server resources. Under my iRule. I'm going to remove that logging. I don't want to be confused because I don't want to log this and the other. There we go. So now let's go scrolling up here. Bob redirect add. Thank you and finished. Alright now that is there.
3:45So let's go back to the iRule. Quick I will list Bob redirect. This is what we want to happen. So I should be sent when I'm on my Windows test box here. It should send me only to this IP address right here. And that is actually our server three in our pool. So when I go back to my Windows test box here momentarily and I bring up the web and access 172 16 101 11 which is this IP address of this virtual server.
4:18I should be sent to server three and this information should be logged. Alright, let's give it a go. Alright, let's open this up and we should be sent to server three. There we go. Server three let's do an incognito. Server three there we go. Alright, let me do another one. Let's do another one. Let's see new incognito. And what do I hit the wrong thing? Alright still server three. Let's bring our terminal in. Let's do a tail var log LTM enter.
4:49And we have a log entry here and it says warning generated common Bob redirect for warning deprecated usage use else or else if. So if I go back here let me get this out. So it did log something it logged in a warning not there and here. Alright I've got an update here. I spent some time troubleshooting this error and it turns out I think the cause was hidden characters from copy and paste.
5:19So what I did was go through here and erase all of any spaces that were in here and that still didn't fix it. So then what I did was go to virtual servers went into my virtual server and I had to actually disable my virtual server right here. Disable it and save it and then go enable it and save it. So I had to bounce my virtual server for those changes to take effect. So again I rules to be honest are hit and miss here because of the intricate details of things like that and I should not have to bounce a virtual server to get an I roll to work but that's what caused it to work.
5:53So let's go see it in action now that it's fixed. So if I open this up I should be going to if we go back here to the I roll real quick. Let's go to I rules our Bob redirect. So here I should be redirected to my server 3 and I should have a login tree that has this information in it. Let's go back here and so let's open an incognito and there we go server 3. Now if I go over here actually here you can't see this is off screen I need to bring in the terminal and I go ahead and do my var log LTM I'm going to tail that and enter and there we go.
6:30This is the entry this is on my Bob redirect and there you go that is the logging. So now we see that that rule is fixed but actually there was nothing wrong with the rule evidently it was hidden characters and I had to bounce that virtual server which is just really blows my mind. Okay but moving on let's go back here. Alright there we go so let's go take a look at another I roll let's go over to I rolls here and this is the Bob redirect URI. Now here what I'm doing is looking at the HTTP request so again I'm going to need to have that HTTP profile in use alright and then if HTTP URI that's our web location after the URL it's going to be our slash all this stuff okay.
7:20If it equals just a slash which is just the default location go ahead and redirect it to the same HTTP host that's what we have here but 50x.html which is an error file that's located on our pool members okay. So this is already on there and that's why I chose it and I wouldn't normally send somebody to this location but this file is the only other HTML in the HTML root file on our test servers so we're just going to do that. So let's go ahead and turn this on and I should hit the server and then be redirected to some type of error page.
7:55So let's see this go over to our virtual servers. There we go let's go to HTTP and there we go resources. Let's go ahead and manage that I'm going to remove the redirect there and I want the scroll up there the URI that one redirect URI and finished. Alright so when I go back to my Windows test box I'm going to close these out. I should receive an error page.
8:26Now when I go here I'm probably just going to get the standard 3 right because this is cached information. Let me bring up an incognito window and make it a little bigger and hopefully this works. Enter oh sure enough there it goes and error occurred and if you look up here at the URI it is sending me to 50x.html and this is an error page. It's not working because so now if I go back to the big IP and I go ahead and I remove that I rule manage remove the I rule and I'm actually going to put this other one either redirection back in say finished and that's because I want to see if it'll log this time.
9:10It's just really acting weird. So we'll go back here and now if I go here and I got to give it a minute I'll close this out. Go back to here and open an incognito and now I should go back to server 3. So hit enter and back to server 3. Alright so that wraps up our I rule traffic steering. Next up is validation. See you there shortly. [BLANK_AUDIO]
Validation
0:00Alright, time for validation. So let's go through some validation questions here. There is a note here If you do plan on taking the F5LTM specialist exam, you will want to spend some time in dev central looking at eye rules I'm telling you you're gonna need to be able to Know the common commands most common and just be able to Decipher what an eye rule is trying to do and we're gonna look at a couple of those down below So question one your company is rolling out an updated web application at a new URL So the new updates going at a new URL All right, and the old URL is dub dub dub nugget labs.net new URL is dub dub dub nugget labs.com So we're going from dot net to dot com Which of the following eye rules will allow clients to connect to the old URL and still be able to access the new web app?
0:50Well, the only way that could happen is if when they connect to the old URL, they're redirected to the new URL So that's what we're trying to do here take a look at the images below and choose the answer that relates to the correct image Have you seen D? Here we go. Here's some code to look at eye rule number a when an HTTP request comes in if The hsp host equals dub dub nugget labs.com redirect it to nugget labs.net That's the opposite of what we're trying to do. So that's not gonna work down here when your HTTP data Now think about this we're looking for the request that's coming in. We're not looking for the data HTTP requests will include the URL which is nugget labs.com that is the HTTP host value Okay, so HTTP data ain't gonna cut it because that's not where the information is we're looking for it It's in the HTTP request. So this has to start with When HTTP requests, so let's scroll on down All right. Oh here C starts with when HTTP requests. That's good If hsp host equals dub dub nugget labs.net anything send it to nugget labs.com
2:13Well, that kind of would work, but we're looking to only redirect dot net to dot com all right So scrolling on down to D this must be the answer when HTTP request the host equals dub dub dub dub nugget labs.net redirect it to dub dub dub nugget labs.com so our answer here is D That is the correct answer. All right scroll on down to number two Your company has recently moved this web application to a new location and to ensure users can still access it at its old location You set up a redirect on the web application server. That sounds like what we just did You've been tasked to setting up an i-roll that will log all of the redirects so you can ensure it's working properly So we're really just wanting to log when the redirects happen. So which of the following i-rolls will do this? Let's find out down here When HTTP responds, so let's talk about this and the last one we looked for the HTTP request Well, the request is going to have the original destination URL But when we have a response, that's when we're going to see that redirection happening So here we're doing an if if HTTP is 3xx Okay, so only if it's has this these 3xx
3:32Then it will log that it's redirecting the client IP address and it'll put the IP and remote address in there All right, let's think about that. Let's compare that to some other options Now here is when HTTP requests, well, I don't want the request the the red irection is in the response So I need to start with when HTTP response. Let me go down That's another request that can't be it and moving on down to d this should be it So when HTTP response if a speed redirects, that means if it's a redirect then go ahead and log this Okay, that looks right. So d would be our answer So again, you need to familiarize yourself with these commands That's why I threw something here that we didn't see or work with maybe so that you could kind of Get the idea So hopefully you went through and used the documentation to look up the HTTP request And some of these other options because that's how we kind of learn through this because there are so many events and commands All right on to question three, what an error occurs with an iRIL in production So that means you're using an iRIL. What will the end result of the connection be?
4:43Well, the answer is Let's see the connection will prompt the user to continue So if they're basically if a user is trying to connect and the iRIL has an error what's going to happen to that connection The user will be prompted to continue. No, the connection will send the user a 404 error. No The connection will be reset. Yes Most likely it's going to be reset And that's what's going to happen when you have an iRIL error Moving down to question four If your iRIL isn't working as expected What would you look for in the var log ltm log file that would indicate an iRIL error?
5:21We talked about this Remember when we looked at an error, it wasn't an iRIL error. It wasn't an iRIL error. It was a tickle error. That's right All right, there we go. That is our review questions For this skill dealing with iRILs. I hope this has been informative for you and i'd like to thank you for viewing [ Silence ]
Frequently asked questions
What does the Working With iRules lesson cover for BIG-IP LTM administrators?
The lesson explains how iRule events such as CLIENT_ACCEPTED and HTTP_REQUEST trigger commands on a BIG-IP virtual server, then shows how to attach an iRule to a virtual server's resources and verify it on live traffic. Team members also configure iRule logging, write a traffic-steering iRule that uses an HTTP redirect based on client IP, and troubleshoot common iRule errors.
How long is the Working With iRules lesson and where does it fit in the F5 301b course?
The lesson runs 47 minutes and is one part of the F5 BIG-IP LTM Specialist: Maintain and Troubleshoot (Exam 301b) course, which takes about 11 hours per learner. The course also covers TCP profiles, configuration consolidation, upgrades, SNMP, syslog and email alerting, AVR, HTTPS troubleshooting, monitors, device issues, and HA/failover.
How do iRules show up on the F5 BIG-IP LTM Specialist exam 301b?
The trainer notes that candidates for the LTM specialist certification will be tested on iRules and need to look at an iRule and figure out what it is doing. He recommends searching DevCentral for iRule articles to get familiar with the most common commands, and the course is built to prepare learners for exam 301b.
What experience should a team member have before taking this iRules lesson?
The course is intermediate and is aimed at BIG-IP administrators or network security admins with roughly 3 to 5 years of enterprise network security experience. IT Directors and Team Leads will get the most value assigning it to people who support production application delivery.
How do you troubleshoot iRule errors and check iRule logs on BIG-IP?
The lesson shows how to review iRule log entries with tail on /var/log/ltm and how to tell a Tcl error apart from a deprecated syntax warning, such as a message to use else or elseif. In the demo, the root cause turned out to be hidden characters from copy and paste, and the virtual server had to be disabled and re-enabled before the iRule behaved as expected.
Why should an IT team review iRules before a BIG-IP upgrade?
The lesson walks through the F5 iRules documentation, including commands and events by version, so administrators can see which iRule commands changed in each release before upgrading. The course is designed for use before upgrade cycles so teams understand the procedures ahead of time and lower change risk.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
Free training library
More free lessons in F5
F5
Creating an F5 BigIP Virtual Lab
Free lesson from BIG-IP Administration Install, Initial Configuration, and Upgrade (F5CAB1) · 1h 2m
F5
Learning ADC and Big-IP Basics
Free lesson from BIG-IP Administration Data Plane Concepts (F5CAB2) · 50m
F5
Confirming Functionality and Upgrading a Big-IP
Free lesson from BIG-IP Administration Support and Troubleshooting (F5CAB5) · 55m
F5
Determining Necessary Configuration Objects
Free lesson from F5 BIG-IP LTM Specialist: Architect, Set up, Deploy (Exam 301a) · 53m
F5
Configuring Health Monitors
Free lesson from BIG-IP Administration Data Plane Configuration (F5CAB3) · 46m
$59
seat / mo, billed annually
