Swallow every few minutes. Sucking on a piece of candy when a plane takes off or lands is helpful. The candy itself doesn't relieve the pressure, but swallowing saliva does. If you are scuba diving, dry swallows have the same effect.
Pinch your nose closed, if swallowing is not enough. Close your mouth if flying. It is not necessary but makes the procedure easier.
Blow through your nose while you are still pinching it closed. Obviously no air can come out your nose but the nasal and ear canals are linked and this could relieve the pressure. Repeat every few minutes or when you feel your ears become blocked again, until you have ascended or descended to the full height/depth.