Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:18:94

They said, "O Dhul-Qarnayn, indeed Gog and Magog are ˹great˺ corrupters in the land. So may we assign for you an expenditure that you might make between us and them a barrier?"  

They said, ‘O Dhū’l-Qarnayn, truly Gog and Magog (read Ya’jūj wa-Ma’jūj or Yājūj wa-Mājūj: these two are non-Arabic names of two tribes and are therefore indeclinable) are causing corruption in the land, plundering and oppressing ˹us˺ when they come forth to attack us. So shall we pay you a tribute, some ˹form of˺ payment (a variant reading ˹for kharjan˺ is kharājan), on condition that you build between us and them a barrier?, an obstruction, so that they will not be able to reach us.
القرآن:١٨:٩٤

قَالُوا يَا ذَا الْقَرْنَيْنِ إِنَّ يَأْجُوجَ وَمَأْجُوجَ مُفْسِدُونَ فِي الْأَرْضِ فَهَلْ نَجْعَلُ لَكَ خَرْجًا عَلَىٰ أَنْ تَجْعَلَ بَيْنَنَا وَبَيْنَهُمْ سَدًّا  

{قالوا يا ذا القرنين إن يأجوج ومأجوج} بالهمز وتركه: هما اسمان أعجميان لقبيلتين فلم ينصرفا {مفسدون في الأرض} بالنهب والبغي عند خروجهم إلينا {فهل نجعل لك خرجا} جعلاً من المال وفي قراءة خراجا {على أن تجعل بيننا وبينهم سداً} حاجزا فلا يصلون إلينا.