Cyclin-dependent kinases (CDKs) are promising targets in chemotherapy. In this study, we report a series of 2-anilinopyrimidine derivatives with CDK inhibitory activity. Twenty-one compounds were synthesized and their CDK inhibitory and cytotoxic activities were evaluated. The representative compounds demonstrate potent antiproliferative activities toward different solid cancer cell lines and provide a promising strategy for the treatment of malignant tumors. Compound5fwas the most potent CDK7 inhibitor (IC50= 0.479 µM), compound5dwas the most potent CDK8 inhibitor (IC50= 0.716 µM), and compound5bwas the most potent CDK9 inhibitor (IC50= 0.059 µM). All the compounds satisfied the Lipinski’s rule of five (molecular weight < 500 Da, number of hydrogen bond acceptors <10, and octanol–water partition coefficient and hydrogen bond donor values below 5). Compound5jis a good candidate for lead optimization because it has a non-hydrogen atom (N) of 23, an acceptable ligand efficiency value of 0.38673, and an acceptable ligand lipophilic efficiency value of 5.5526. The synthesized anilinopyrimidine derivatives have potential as anticancer agents.