This document proposes a method to detect and prevent denial of service (DoS) attacks in mobile ad hoc networks using a trust-based mechanism. It involves calculating trust values for each node based on their behavior and activity, including the number of routing packets sent and received. Nodes with low trust values that are suspected of attacks will be isolated from the network. The method was tested in an ad hoc network simulation using NS-2 and showed improved performance metrics like higher packet delivery ratio, lower delay, jitter and dropping ratio compared to a network under DoS attack. This demonstrates that the trust-based mechanism can effectively detect DoS attackers and secure routing in the mobile ad hoc network.