Update 4: apparently connectivity is very spotty at the moment of this writing, meaning that this fix may or may not work for you. It's worth mentioning that a failed connectivity check doesn't necessarily mean the PS4 won't connect online. A better indicator is whether you see your friend list or not after setting the relevant values.  For instance, my PSN Sign-in test fails, but i'm still connected and my console works normally.

Update 3: The fix has been officially endorsed by Sony.

Update 2: The fix apparently works again, so try it, and it may get you online.

Update: while the fix worked this morning, it doesn't anymore. Sony posted a message on the PlayStation Blog apologizing for the interruptions and promising news as soon as the services will be restored.

The original article can be found below.

If you're still unable to access the PSN, despite the fact that the services are gradually coming back online, here's a temporary fix that might help you.

Go to Settings -> Network -> Set Up Internet Connection on your PS4, select "Custom," leave all your settings as they were, but change MTU to 1473.

It's very likely that you'll be able to connect with no issue even if you weren't before applying this small fix.

Hopefully this won't be needed soon, but if you're still having problems and want to connect in a hurry, trying this is a good bet. Just remember to change it back to 1500 once the problems are fully solved.