Security and privacy of conventional homogeneous networks such as MANETs and WSNs have been widely studied in the literature. However, with the emergence of a new generation of non-homogeneous networks, the existing solutions on privacy and anonymity should be re-investigated from a practical point of view. In the internet of things (IoT), sensitive and confidential contents are transferred over machine to machine (M2M) networks. This volume of private data in the M2M networks is like a gold mine of data for adversaries; hence, it is crucial to ensure anonymity and trust of the identities in such networks. The main objective of this article is to provide a comprehensive overview on anonymity-related attacks and the privacy solutions for M2M networks. First, the architecture and characteristics of M2M networks are reviewed and the potential targets of adversaries along with the privacy threats are described. Then, the security solutions to countermeasure the threats and to maintain privacy in M2M networks are categorized and surveyed.