How to determine what ports X is listening on?

Zhro picture Zhro · Jul 23, 2013 · Viewed 15.1k times · Source

My use case is that I am running nx over ssh and the local proxy connects to the remote host via tunneling. Because it's tunneled, I tell nx to connect to localhost:port. The problem is that I need to perform X authentication and if I hit the local X server by accident instead of the remote one, I get an authentication error.

How can I determine what port the local X server is listening on so that I can avoid it when setting up my tunnel?

My current workaround is to avoid tunneling with any local port which already has another application listening on it.

Answer

Andrey Sidorov picture Andrey Sidorov · Jul 25, 2013

It's usually screen number + 6000. For example, if $DISPLAY is :5 port number is 6005