Traffic analysis attacks are passive attacks that try to deduce the traffic pattern based on the eavesdropped information. Through analyzing the packet traffic, it can deduce the location of strategic nodes, and then launch an active attack to those locations, such as DoS attack. Therefore, defending against a traffic analysis attack is to prevent the adversary from tracing the location of critical sensor nodes. Due to the open wireless communication media exposing the context information to adversaries, we cannot use traditional encryption and authentication to prevent the adversaries from eavesdropping on the wireless communication. In this paper, we propose three schemes to defend against the traffic analysis attacks. Firstly, a random routing scheme (RRS) is proposed to provide path diversity. Secondly, we combine RRS with a dummy packet injection scheme (DPIS) to confuse the adversary by tracing or tracing back the forwarded packet to reach the receiver or source. Finally, an anonymous communication scheme (ACS) is proposed to hide the identities of all nodes that participate in packets transmission. Through security analysis and simulation, we can see that our proposed schemes can efficiently defend against traffic analysis attacks, take less delivery time and achieve uniform energy consumption.