In this paper, we propose an ant-based algorithm for dynamic routing and wavelength assignment (RWA) in WDM optical networks under the wavelength continuity constraint. By adopting a new routing table structure and keeping a number of ants in the network to cooperatively explore the network states and continuously update the routing tables, our new ant algorithm can efficiently support the ants’ foraging tasks of route selection and wavelength assignment in WDM networks, and allow a connection to be setup promptly on arrival with a small setup time. Extensive simulation results based on the ns-2 network simulator indicate that the proposed algorithm can adapt well to traffic variations and achieves a lower blocking probability than the fixed routing algorithm.