Rotating machinery plays a critical role in large-scale equipment, and its operational condition significantly influences the stability and safety of the equipment. Therefore, it is imperative to improve the accuracy of fault diagnosis. While deep learning has been widely utilized for fault diagnosis, the effectiveness of the model heavily relies on hyperparameter configuration. Current deep learning methods often necessitate human intervention to fine-tune these hyperparameters, leading to a time-consuming and potentially subjective process. Furthermore, although various meta-heuristic algorithms have been employed for optimizing hyperparameters, these methods are computationally intensive and susceptible to converging on local optimal solutions when dealing with high-dimensional non-convex hyperparameter spaces. To tackle this issue, this paper proposes a cross-domain fault diagnosis using convolutional attention network (CAN) with an improved dung beetle optimization (IDBO) algorithm, called IDBO-CAN algorithm. Firstly, an IDBO algorithm is designed, which mainly uses chaotic local search, levy flight strategy and adaptive lognormal distribution variation to enhance the global optimization capability of the dung beetle optimization algorithm. Secondly, the setting of hyperparameters significantly affects the performance of the CAN using a one-dimensional convolutional neural network. The IDBO algorithm is employed to automatically determine better hyperparameters for CAN. Finally, the performance of IDBO and IDBO-CAN algorithms are evaluated by 13 benchmark functions and multi-source datasets. The experimental results show that IDBO and IDBO-CAN algorithms have excellent performance on many benchmark functions and datasets.