Internet of Things (IoT) a growing phenomenon, refers to the seamless integration of things into the information network. The security in IoT is tampered because of the various attacks which happen due to resource constrained nature of the devices in the network. Thus, although IoT is evolving as an attractive next generation networking paradigm, it can be adopted only when the security issues are resolved. This implies that, in a dynamic and collaborative IoT environment, the devices need to be trustworthy. This paper proposes a gateway based trust management system and an algorithm for computation of trust for the devices. The system focuses on making the computations on the devices lightweight and the network robust. The proposed system is tested against various IoT attacks and results demonstrate that it can clearly identify the malicious device if any, in the IoT network.