Restricting TCP Session Direction
Problem
You want to filter TCP sessions so that only the client device may initiate the application.
Solution
You can use the established keyword to restrict which device is allowed to initiate the session. In the following example, we want to allow the client device to telnet to the server, but not the other way around:
Router1#configure terminalEnter configuration commands, one per line. End with CNTL/Z. Router1(config)#access-list148permit tcp any eq telnet any establishedRouter1(config)#access-list148deny ip any anyRouter1(config)#interfaceRouter1(config-if)#FastEthernet0/0ip access-group148inRouter1(config-if)#exitRouter1(config)#endRouter1#
Discussion
In this example, the interface will accept incoming TCP packets only if they have a TCP source port number of 23 (Telnet), and only if this TCP session is already established. It does not restrict the destination port number, because this would be whatever random high-numbered port the initiating device had originally selected for its source port when it started the session.
The router considers an established TCP connection to be one that has either the RST or ACK bits set. We discuss these TCP header flags in more detail in Recipe 19.4. Because this does not include the SYN bit in particular, it is impossible to create a new TCP connection.
Note that you could actually write the same thing explicitly as two rules:
Router1(config)#access-list148permit tcp any eq telnet any ackRouter1(config)# ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access