Due to using less secured and movable devices in Internet of Things (IoT) platform, cyber‐attacks have been a major issue nowadays. Different researches have been conducted to detect the probable security attacks, but faced constraints like storage, computation cost, system failure and high latency. Existing systems require continuous monitoring, controlling, and collecting the data in entire network for delivering services with the maximum security and defense mechanism against cyber‐attacks. In this context, a decentralized mechanism of security has been presented in this article using a software‐defined network (SDN) integrated with blockchain for IoT in mobile edge and fog computing. The SDN continuously monitors and analyzes the system traffic for providing an attack identification model. The blockchain has been used to overcome the failure issues addressed in the existing models by delivering decentralized attack identification scheme which detects attacks in fog and reduces it in the edge node.