Forum Discussion
shawmcbigdis_84
Nimbostratus
Jul 23, 2009SNAT iRule problem
I'm trying to get snat to work for only outbound internet connections, not for internal addresses. I am using the following rule;
when SERVER_CONNECTED {
Compare destination address with the pre-defined
class of RFC1918 non-routable addresses
If not in that group, automap-SNAT the connection
log local0. "in SERVER_CONNECTED with [IP::server_addr]"
if {not [matchclass [IP::server_addr] equals ::private_net] } {
snat automap
log local0. "[IP::client_addr] client address"
log local0. "[IP::local_addr] local address"
}
}
the rule does not throw any errors, but the snat is not functioning. When I have this rule as in place on our default rout VIP with SNAT off on the VIP it logs the client and local IP's as the IP of the physical box. When I turn snat on on hte VIP it logs the local ip of the BigIP for the client address (and NAT'ing works obviously)
I'm pretty new to, and not very good at this whole iRule thing, so I'm sure it's something little that I'm missing.
Thanks
- dennypayne
Employee
I believe the problem is that the SERVER_CONNECTED event indicates that the server connection has already been established, so it's too late to SNAT at that point. You probably need to implement your logic for SNATing within CLIENT_ACCEPTED. - hoolio
Cirrostratus
Hi Shawn, - shawmcbigdis_84
Nimbostratus
Denny and Aaron, - hoolio
Cirrostratus
Try changing IP::server_addr in your log statement to IP::local_addr. - shawmcbigdis_84
Nimbostratus
Aaron, that worked perfectly! I don't understand why though? Why would a log statement stop the NAT from functioning properly? - hoolio
Cirrostratus
IP::server_addr tries to return the remote address from the serverside connection. Because no serverside connection has been established in CLIENT_ACCEPTED, the runtime error (in the log statement) causes an invalid state for the connection. TMM sends a reset to the client to close the connection. To handle runtime errors gracefully and prevent resets, you can use the catch command(Click here).when CLIENT_ACCEPTED { Debug logging log local0. "[IP::client_addr]:[TCP::client_port]: New TCP connection to destination IP:port [IP::local_port]:[TCP::local_port]" Compare destination address with the pre-defined class of RFC1918 non-routable addresses If not in that group, automap-SNAT the connection if {not [matchclass [IP::local_addr] equals ::private_net] } { snat automap } } when SERVER_CONNECTED { Debug logging log local0. "[IP::client_addr]:[TCP::client_port]: New TCP connection to destination IP:port [IP::local_port]:[TCP::local_port] \ using source [IP::local_addr]:[TCP::local_port]" }
- shawmcbigdis_84
Nimbostratus
OK, got it. Awesome. Thanks a ton for the help. - hoolio
Cirrostratus
What VIPs do you have defined that could potentially match the destinations? Clients will only be able to connect to one virtual server for the full request and response to LTM and to the pool member. The iRule would only be triggered for virtual servers that it is configured for under the VIP's resources tab in the GUI.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects