Sulfadimethoxine (SDM) as an extensively employed veterinary drug causes potential threats to human health. Herein, a dual recognition mode novel upconversion fluorescence biosensor was designed based on inner filter effect (IFE) to sensitively and rapidly detect SDM in aquatic samples. Aldehyde-functionalized magnetic nanoparticles (MNPs) were applied to recognize and capture SDM, followed by specifically bond with biotin-labeled aptamers. The upconversion nanoparticles and the colored products resulting from the enzyme-catalyzed oxidation of 3,3,5,5-tetramethylbenzidine exhibited an IFE quenching process. Under the optimal condition, the results displayed the fluorescence intensity was correlated with the concentration of SDM within the range of 0.5–1000 ng⋅mL−1 achieving a low limit of detection of 0.13 ng⋅mL−1. The SDM detection system was further employed in the spiked aquatic samples with good recoveries (88.41–96.78 %). Consequently, the constructed fluorescence biosensor provided broad prospects for accuracy and rapid detection of SDM.