In recent years, the adoption of 5G has significantly increased due to its numerous benefits, including high availability, lower latency, improved reliability, and high performance. To manage packet flow, 5G relies on Software-Defined Networking (SDN) that employs software controllers and Application Programming Interfaces (APIs) to route packets and communicate with the hardware, providing advantages like high efficiency, low cost, and dependability. However, due to centralized control, SDN controllers are vulnerable to various cyber-attacks, including Distributed Denial of Service (DDoS), Denial of Service (DoS), Password Brute Forcing, Web Attacks, etc. This paper proposes a framework that comprises a hybrid feature selection method and an ensemble machine learning model. The proposed ensemble model combines the strengths of three different machine learning (ML) classifiers to create a voting classifier for classifying traffic in SDN. Additionally, the optimal value for the hyperparameters of each classifier is obtained through hyperparameter tuning. Finally, the experimental analysis of the proposed model using the InSDN dataset shows 99.96% accuracy, highlighting the proposed model’s effectiveness in addressing the limitations of the existing approaches and detecting multiple attacks in the SDN context.