Packet classification is a key technique for filtering network packets in a router, and the rules determine which action is taken for each packet. However, packet classification suffers from a degradation of performance when man-made rules contain some overlap, useless, or redundancy rules. When we implement a packet classification system in a real network, we find that the rules have the characteristics of a social community. On the basis of community detection, some rules can be clustered by similarity and share a common action. Therefore, the rules that affect performance can be optimized, which will be beneficial for matching time, memory usage and rule updating. In this paper, we present a ComCuts (community detection cuttings) algorithm for packet classification based on a counting bloom filter, and a rule similarity algorithm for clustering. Experimental results show that our algorithm reduces matching time by 8% and decreases memory usage by 50% compared to a HiCuts algorithm. Furthermore, our clustering scheme uses elasticity scope to adopt to a frequently updated system, especially in a SDN network.