There is a tube from behind the ear drum to the throat called the Eustachian tube.
This is to equalise the pressure, and swallowing tends to open it to allow air to get through.
Opening the jaw wide repeatedly has a similar effect, but you do feel like a burk.
If you have a cold, mucus can obstruct the tube, which is why you were offered a decongestant inhalant. Well worth taking decongestant medicine before the flight if you know you are bunged up.
Pinching the nose, blowing gently and swallowing at the same time can force air through, but this can be dangerous if you blow too hard and the tube is blocked. This is known as the Valsalva maneuver.
You will feel your ears pop after take off painlessly, as the air forces its way out. The pain happens on descent as it is harder for the air to get back in.
Parents ofen worry because their babies cry on descent, but actually crying is the best thing the baby can do to open the tubes up.