Software-defined network (SDN) platforms play a key role in providing security against today's Internet attacks. SDNs decouple the control plane from the data plane to maximize network performance. A DDOS attack is one of several in cloud-based networks. SDNs play a crucial role in controlling DDoS attacks and protecting end nodes like IoT nodes, as well as other computing devices, in large-scale cloud networks. This paper provides an efficient approach to DDoS attack detection and prevention using machine learning algorithms. The paper analyses the performance of SDNs in IoT systems, incorporating a huge set of computing devices that use multi-controllers. It also proposes an effective method to handle DDoS attacks. DDoS attacks are generated from IoT end devices in the infrastructure layer, which targets resources via an SDN-controlled testbed. The proposed ML method outperforms existing methods in terms of accurately and effectively detecting and mitigating flooding DDoS attacks with 99.99% accuracy. The proposed work's results are also compared to the results of other articles to prove the effectiveness of the results.