Cilia are important for the interaction with environments and the proper function of tissues. While the basic structure of cilia is well conserved, ciliated cells have various functions. To understand the distinctive identities of ciliated cells, the identification of cell-specific proteins and its regulation is essential. Here, we report the mechanism that confers a specific identity on IL2 neurons in Caenorhabditis elegans, neurons important for the dauer larva-specific nictation behavior. We show that DAF-19M, an isoform of the sole C. elegans RFX transcription factor DAF-19, heads a regulatory subroutine, regulating target genes through an X-box motif variant under the control of terminal selector proteins UNC-86 and CFI-1 in IL2 neurons. Considering the conservation of DAF-19M module in IL2 neurons for nictation and in male-specific neurons for mating behavior, we propose the existence of an evolutionarily adaptable, hard-wired genetic module for distinct behaviors that share the feature "recognizing the environment."