Self-signed certificates tend to expire at the worst moment. For a test setup I don’t want a new key and a new request, I just want more days on the one I have.
openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem
With -signkey, OpenSSL signs the certificate again with the private key you give it. The docs say that the issuer is set to the subject, so the result is self-issued, and that all certificate extensions are retained by default. -clrext drops them. Unless you pass -preserve_dates, the start date becomes the current time and the end date follows from -days. The default is 30 days, which is why a short test certificate dies so soon.
On a test certificate that has a subjectAltName, the new file gets fresh dates and keeps the same public key and the same DNS: name. The serial number stays the same too, which I would not rely on if a client keeps a list of serials.
Check the result with:
openssl x509 -in cert-new.pem -noout -dates -ext subjectAltName
Caveats: this only makes sense for a certificate that signs itself. For one that a CA signed, you need a new request or a new signing step. Also, -days and -preserve_dates cannot be used together. And anything that pinned the old certificate will notice the change, because the dates and so the fingerprint are different.
Further reading: openssl-x509 documentation