DFT calculations were used to investigate adsorption of F-, Cl-, Li+ and Na+ ions on the exterior surface of Mg12O12 nanocage in the gas phase and water media. The most favorite position for adsorption of the studied anions and cations are atop of Mg and O atoms of Mg12O12, respectively. The strongest interaction is obtained when fluoride is located atop of Mg atom with the adsorption energy of -2.92 eV. In water media, adsorption energy of ions is reduced due hydration of ions and nanocage. Adsorption of the studied ions on the Mg12O12 nanocage is compared with adsorption of these ions on AlNNT surface. It is shown that Mg12O12 is more convenient adsorbent for fluoride ion than AlNNT.