We demonstrate a robust and versatile solution for locking the continuous-wave dye laser for applications in laser cooling of molecules which need linewidth-narrowed and frequency-stabilized lasers. The dye laser is first stabilized with respect to a reference cavity by Pound-Drever-Hall (PDH) technique which results in a single frequency with the linewidth 200 kHz and short-term stabilization, by stabilizing the length of the reference cavity to a stabilized helium-neon laser we simultaneously transfer the ± 2 MHz absolute frequency stability of the helium-neon laser to the dye laser with long-term stabilization. This allows the dye laser to be frequency chirped with the maximum 60 GHz scan range while its frequency remains locked. It also offers the advantages of locking at arbitrary dye laser frequencies, having a larger locking capture range and frequency scanning range to be implemented via software. This laser has been developed for the purpose of laser cooling a molecular magnesium fluoride beam.