diff --git a/src/squeue/opts.c b/src/squeue/opts.c
index f6e2992b2d72f223783bb7751eea857d41a75f03..cdf673a688ee618bdd52ad9a94f8b66f4c779d45 100644
--- a/src/squeue/opts.c
+++ b/src/squeue/opts.c
@@ -97,6 +97,7 @@ extern void
 parse_command_line( int argc, char* argv[] )
 {
 	char *env_val = NULL;
+	char *nodes;
 	bool override_format_env = false;
 	int opt_char;
 	int option_index;
@@ -150,7 +151,7 @@ parse_command_line( int argc, char* argv[] )
 	}
 	if (getenv("SQUEUE_PRIORITY"))
 		params.priority_flag = true;
-
+	nodes = NULL;
 	while ((opt_char = getopt_long(argc, argv,
 				       "A:ahi:j::lL:n:M:O:o:p:Pq:R:rs::S:t:u:U:vVw:",
 				       long_options, &option_index)) != -1) {
@@ -298,8 +299,7 @@ parse_command_line( int argc, char* argv[] )
 				      optarg);
 				exit(1);
 			}
-			if (!_check_node_names(optarg))
-				exit(1);
+			nodes = xstrdup(optarg);
 			break;
 		case OPT_LONG_HELP:
 			_help();
@@ -377,6 +377,14 @@ parse_command_line( int argc, char* argv[] )
 		/* Replace params.nodename with the new one */
 		hostset_destroy(params.nodes);
 		params.nodes = nodenames;
+		/* Check if all node names specified
+		 * with -w are known to the controller.
+		 */
+		if (!_check_node_names(nodes)) {
+			xfree(nodes);
+			exit(1);
+		}
+		xfree(nodes);
 	}
 
 	if ( ( params.accounts == NULL ) &&
@@ -1936,6 +1944,9 @@ _check_node_names(char *names)
 	char *host;
 	hostlist_iterator_t itr;
 
+	if (names == NULL)
+		return true;
+
 	cc = slurm_load_node(0,
 			     &node_info,
 			     SHOW_ALL);