It is the duty of Muslim nations to safeguard their territories against any form of transgression whether actual or potential. In many hadiths Muslims are encouraged to take part in this indispensable service and they have been promised magnificent rewards in the Hereafter for fulfilling this task for the sake of Almighty Allah.
Below is the fatwah of the Standing Committee for Islamic Research and Ifta in Saudi Arabia regarding al-Ribat (Garrisoning) in Islam:

Al-RibatFiSabil Allah means garrisoning Muslim frontiers (i.e. keeping a guarding army ready to defend Muslim frontiers against enemies and against any attempts to invade Muslim countries). Many hadiths have been reported declaring the virtue of guarding Muslim frontiers in the cause of Allah. The following are some of these hadiths:

1. It was related in SahihAl-Bukhari on the authority of SahlibnSa`d Al-Sa`idy (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said, “To guard Muslim frontiers in Allah’s Cause for one day is better than the world and everything it contains.” (Sahih al-Bukhari)

2. It is even considered better than voluntary fasting and prayers, as it was narrated in SahihMuslim on the authority of Salman Al-Farisi (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said, “Guarding the Muslim frontiers for a day and a night is better (in point of reward) than fasting for a whole month and offering Qiyam Al-Layl (Night Vigil Prayer) every night.” (Sahih Muslim)

3. Moreover, those who do this duty will be saved from the trials of the grave and the rewards of their deeds will not cease by their death. In Musnad (Hadith compilation of) Imam Ahmad, SahihIbnHibban, SunanAbu Dawud and SunanAt-Tirmidhi, there is a narration on the authority of Fadalahibn `Ubayd (may Allah be pleased with him) that he said: I heard the Messenger of Allah (peace and blessings be upon him) saying, “The deeds of every deceased person come to a halt by his death except the one who is on the frontier in the cause of Allah, for their deeds will continue to grow and they will be safe from the trials of the grave.” [At-Tirmidhi said that this is a hasansahihhadith (good and/or authentic hadith)].