In a wireless sensor networks, the communication of the network will be affected by the attacks. The most common attacks are denial of service, packet droppers and packet modifiers. In a wireless sensor networks, the communication between the hosts is static (the hosts addresses are predefined). If any attacks disrupt the communication then the network performance degrades. To address this problem, a simple yet effective scheme is proposed i.e., the communication between the hosts will be dynamically perform. By this paper, the performance of the network will be the effective and efficient.