openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 \ -nodes -keyout example.key -out example.crt \ -subj "/CN=example.com" \ -addext "subjectAltName=DNS:example.com,DNS:www.example.com,IP:127.0.0.1"

Documentation:
https://www.openssl.org/docs/man1.1.1/man1/openssl-req.html