Internal energy (U) of a system is the energy possessed by the system due to molecular motion and molecular configuration. The internal kinetic energy UK of the molecules is due to the molecular motion and the internal potential energy UP is due to molecular configuration.
Thus U = UK + UP
It depends only on the initial and final states of the system. In case of an ideal gas, it is assumed that the intermolecular forces are zero. Therefore, no work is done, although there is change in the intermolecular distance. Thus UP = 0. Hence, internal energy of an ideal gas has only internal kinetic energy, which depends only on the temperature of the gas. In a real gas, intermolecular forces are not zero. Therefore, a definite amount of work has to be done in changing the distance between the molecules. Thus the internal energy of a real gas is the sum of internal kinetic energy and internal potential energy. Hence, it would depend upon both the temperature and the volume of the gas.