diff --git a/tmcd/tmcd.c b/tmcd/tmcd.c
index d20c484a50d25b0e0bcc654a41c145fb68d74880..264d87b0c20a4428e550d8b23033f4453c1a06cf 100644
--- a/tmcd/tmcd.c
+++ b/tmcd/tmcd.c
@@ -6704,7 +6704,7 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
 	 * Widearea nodes have wanodekeys that should be used to get
 	 * the nodeid.
 	 */
-	if ((nodekey != NULL) && (strlen(nodekey) > 1)) {
+	if ((nodekey != NULL) && (strlen(nodekey) > 1) && !reqp->isvnode) {
 		res = mydb_query("SELECT t.class,t.type,n.node_id,"
 				 " n.jailflag,r.pid,r.eid,r.vname, "
 				 " e.gid,e.testdb,n.update_accounts, "
@@ -6758,6 +6758,12 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
 				"r.external_resource_key='%s'",
 				reqp->external_key);
 		}
+		else if (nodekey != NULL && strlen(nodekey) > 1) {
+			sprintf(clause,
+				"(np.node_id IN "
+				"     (SELECT node_id FROM widearea_nodeinfo "
+				"      WHERE privkey='%s')) ", nodekey);
+		}
 		else {
 			sprintf(clause,
 				"(i.IP='%s' and i.role='ctrl') or "