We establish a model to investigate the effect of clustering of impurities on the ferromagnetism in dilute magnetic semiconductors (DMS). The Curie temperature T is calculated by the mean-field theory on a lattice with randomly distributed clusters of magnetic impurities which are interacting with each other by carrier mediated RKKY exchange coupling together with the nearest-neighbor (NN) direct exchange interaction. We consider different types and sizes of the clusters and find that the clustering of impurities can either enhance or reduce T, depending on the type and strength of the NN exchange interaction. If the NN interaction is antiferromagnetic and strong compared with the RKKY interaction, the clustering will reduce T. On the other hand, if it is ferromagnetic interaction or weak antiferromagnetic one, the clustering can enhance T. The trend of enhancing T is magnified if the average size of clusters increases. The clustering also changes the distribution of polarizations of impurities. The obtained results provide natural explanations on the fact that the ferromagnetism of DMS samples depends on the preparing and annealing processes even though the density of the magnetic impurities is kept the same.