The electronic and magnetic properties of d0 dilute magnetic semiconductors formed by rock-salt structured magnesium oxide (MgO) doped with C are systematically studied based on first-principles calculations and the Ising model. It is shown that the electronic holes of p states are generated due to the impurity carbon replacing oxygen in MgO, and the magnetic moment of 2μB is introduced by each C impurity. The polarization energy and formation energy of C-doped MgO are calculated, and the magnetization energy of C-doped MgO is also calculated which is used to obtain the exchange constant between C impurities. By means of the Ising model, we simulated the magnetization and the susceptibility of the doped system with increasing temperature and obtained the Curie temperature of C-doped MgO.