Disable X Server Listening TCP Port-6000

X server usually starts listening TCP Port 6000 for remote network connection. Hence, one must be careful should the server exposes its connections via the Internet. This section guides you on how to disable X server from listening TCP Port 6000.

Disable By Firewall

One very easy way is to disable the TCP port by Firewall such as ufw or iptables. One would just need to set the rule to only accepts localhost. This applies to all kinds of desktop managers (DM).

Apply Nolisten to TCP

This works for XDM desktop manager only. Another way is to configure the startx not to listen to TCP port by default. This is done by editing /etc/X11/xinit/xserverrc (create one if not available) and add the following:

#!/bin/sh
exec /usr/bin/X11/X -dpi 100 -nolisten tcp

Note this different desktop manager has different configuration file and location. For example, GDM must configure /etc/gdm/gdm.conf instead with:

DisallowTCP=true

Hence, if you opt for this path, you must consult your desktop manager manual before performing any edits.

That's all about disabling X server to listen TCP Port-6000.