With the ever-increasing usage of Internet of Things (IoT) applications in every aspect of our lives, protecting IoT networks from security threats has become a significant challenge. Machine learning techniques are widely used to detect anomalous behavior in networks. However, most of the existing machine learning techniques train a model on a whole batch of data at a time. This is not suitable for many IoT networks where new data is constantly arriving in a stream. To address this issue, we propose an online Machine Learning (ML) model that processes a data stream element simultaneously, keeps learning, and does not revisit past data. We used two IoT datasets, DS2OS and loophole attack datasets, to evaluate the performance of our proposed online machine learning model against the traditional ML model in terms of accuracy and F-measure. The experimental results show that our proposed decision tree (DT) based online model has an accuracy of 98.8\% and 89.3\% for the DS2OS and loophole attack datasets, respectively. The results also ensure that the proposed model can detect anomalies effectively even in unbalanced classes.