17c662
diff --git a/src/cli-args.def b/src/cli-args.def
17c662
index c661f458b..11d66ae8a 100644
17c662
--- a/src/cli-args.def
17c662
+++ b/src/cli-args.def
17c662
@@ -80,6 +80,13 @@ flag = {
17c662
     doc       = "Connect, establish a session and rehandshake immediately.";
17c662
 };
17c662
 
17c662
+flag = {
17c662
+    name      = sni-hostname;
17c662
+    descrip   = "Server's hostname for server name indication extension";
17c662
+    arg-type  = string;
17c662
+    doc      = "Set explicitly the server name used in the TLS server name indication extension. That is useful when testing with servers setup on different DNS name than the intended. If not specified, the provided hostname is used.";
17c662
+};
17c662
+
17c662
 flag = {
17c662
     name      = starttls;
17c662
     value     = s;
17c662
diff --git a/src/cli.c b/src/cli.c
17c662
index 82d8e1166..f3d159a29 100644
17c662
--- a/src/cli.c
17c662
+++ b/src/cli.c
17c662
@@ -638,7 +638,10 @@ static gnutls_session_t init_tls_session(const char *hostname)
17c662
 	/* allow the use of private ciphersuites.
17c662
 	 */
17c662
 	if (disable_extensions == 0 && disable_sni == 0) {
17c662
-		if (hostname != NULL && is_ip(hostname) == 0)
17c662
+		if (HAVE_OPT(SNI_HOSTNAME)) {
17c662
+			gnutls_server_name_set(session, GNUTLS_NAME_DNS,
17c662
+					       OPT_ARG(SNI_HOSTNAME), strlen(OPT_ARG(SNI_HOSTNAME)));
17c662
+		} else if (hostname != NULL && is_ip(hostname) == 0)
17c662
 			gnutls_server_name_set(session, GNUTLS_NAME_DNS,
17c662
 					       hostname, strlen(hostname));
17c662
 	}
17c662
-- 
17c662
2.14.3
17c662