Offering prayers to ask for rain (known in Arabic as al-Istisqaa') is a Sunnah which has been confirmed by authentic narrations and by the practice of the early generations of Islam.
Ibn Qudāmah said:
"Prayer for rain is a confirmed Sunnah, proven by the practice of the Messenger of Allah (may the blessings and peace of Allah be upon him) and of his successors." [al-Mughni, 2/148]
It was narrated that Is-hāq ibn 'Abdūllah ibn Kinānah said: al-Waleed ibn 'Uqbah, who was the governor of Madinah, sent me to ask Ibn ‘Abbās about the prayer of the Messenger of Allah (may the peace and blessings of Allah be upon him) for rain. He said:
The Messenger of Allah (may the peace and blessings of Allah be upon him) went out wearing modest clothes, walking humbly and beseeching Allah, until he reached the prayer place, where he ascended the minbar, but he did not give a khutbah like this khutbah of yours; rather he continued to offer supplication (du'aa), beseech Allah and recite takbeer, then he prayed two rak'ah, as he used to pray at Eid. [Abū Dāwood: 1165, at-Tirmidhī: 558, an-Nasā'ī: 1506, and Ibn Mājah: 1266]
There is a narration of 'Aa'ishah (may Allaah be pleased with her) which states that the Prophet (may the peace and blessings of Allaah be upon him) set a day when the people should go out. 'Aa'ishah said:
"The Messenger of Allah (may the peace and blessings of Allah be upon him) went out when the rim of the sun appeared…"
This narration clearly indicates that a day was set when the people were to go out to pray the rain prayer, even though it does not name this day. It also mentions that the time for the prayer is at the earliest time after which prayer can be resumed following sunrise.