This is a great question.
First we have to understand why this happens.
The middle ear space is linked to the back of the nose via the auditory tube as below.
Sometimes a really bad infection, like a sinus infection can cause the phelgm to actually go into the middle ear space via the auditory tube.
After this phelgm goes inside, it kind of stays there and cause a blocked feeling of the eardrum.
1) You could try the valsalva maneuver.
Try to close your nose and blow gently. If it hurts, you have to stop.
You also can try to blow through a straw. There are other ways as well, you can try to google.
2) If it fails or hurts, you might need to see a doctor. You might even need antibiotics or other treatment.
3) Try to avoid taking a flight or diving while you are having this.
Take care!