Port 5900 (VNC)
Key facts
- Port
- 5900
- Protocols
- TCP
- Range
- Registered port, 1024-49151
- IANA service name
- rfb
IANA assigns ports in this range to services on request, under RFC 6335.
About port 5900
Port 5900 is the default port of VNC, a way to view and control the desktop of a computer or server remotely. It runs over TCP.
VNC is based on the RFB (Remote Framebuffer) protocol, defined in RFC 6143. According to the standard, the client connects to the server on port 5900, and on a computer running several VNC servers, server number N usually listens on port 5900+N, for example 5901 for display number 1. IANA registers port 5900 for the rfb service.
What port 5900 is used for
- A graphical desktop on a Linux server: working with graphical applications on a remote server, when the command line isn't enough.
- Remote support: viewing and controlling another computer's screen, for example to help a user.
- Virtual machine consoles: many virtualization platforms show the virtual machine's screen through VNC.
Port 5900 in the firewall
The recommended approach is to keep the VNC ports closed to the internet and connect through an SSH tunnel: the client connects to a local port on your computer, and the traffic travels encrypted over port 22. When you must open the port, allow it only from your IP address:
- UFW:
ufw allow from 203.0.113.10 to any port 5900 proto tcp - firewalld:
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10" port port="5900" protocol="tcp" accept'
When you restrict access to specific addresses, also delete any earlier rule that opened the port to everyone, or that general rule will keep allowing access from any address.
When the VNC server listens on a different port, for example 5901, replace the port number in the rules.
Risks and security
According to RFC 6143, the protocol itself doesn't encrypt the traffic, and VNC Authentication, the protocol's basic password method, uses only the first eight characters of the password and isn't meant for untrusted networks. That's why it is common to add a layer of protection:
- Connect through an SSH tunnel or a VPN, so all the traffic is encrypted.
- Set the VNC server to listen only on 127.0.0.1 when you use an SSH tunnel.
- Choose a strong VNC password, different from the user's password on the server.
- Turn off the VNC server when you don't need it.
Commands to check and configure
-
ss -tlnp | grep -E ':590[0-9] 'Shows the processes listening on ports 5900 to 5909 and the address each of them listens on (requires root privileges).
-
ssh -N -L 5901:127.0.0.1:5901 user@server.example.comOpens an SSH tunnel from your computer to the server. Then point your VNC client at localhost:5901, and the traffic travels encrypted.
-
nc -zv server.example.com 5900Checks from your computer whether port 5900 is open on the server.
-
ufw deny 5900/tcpBlocks incoming connections to port 5900 (UFW).
-
ufw allow from 203.0.113.10 to any port 5900 proto tcpAllows access to port 5900 only from the specified IP address (UFW).
-
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10" port port="5900" protocol="tcp" accept'Allows access to port 5900 in firewalld only from the specified IP address. Then run firewall-cmd --reload.
Port 5900 in the IANA registry
| Port | Protocol | Service | IANA registry description |
|---|---|---|---|
| 5900 | TCP | rfb | Remote Framebuffer |
| 5900 | UDP | rfb | Remote Framebuffer |
Data source: IANA Service Name and Transport Protocol Port Number Registry (opens in a new tab)
Port 5900 FAQ
What's the difference between VNC and Remote Desktop (RDP)?
VNC transmits the image of the existing screen and works on many operating systems, which is why it is common on Linux servers and in virtual machine consoles. Windows Remote Desktop works on port 3389 and opens a separate session for the user on the server. The RDP errors page has solutions for common connection problems.
How do I connect to VNC securely?
Open an SSH tunnel with ssh -N -L 5901:127.0.0.1:5901 user@server.example.com, and point your VNC client at localhost:5901. This way the VNC port stays closed in the firewall, and the traffic travels encrypted. The SSH hardening page has settings that also protect the SSH connection itself.
Why is the VNC server listening on port 5901 and not on port 5900?
Each VNC server on a computer gets a display number, and its port is 5900 plus the display number. Display number 1 listens on port 5901, display number 2 on port 5902, and so on.
Do I need to open port 5900 in the firewall?
When you connect through an SSH tunnel or a VPN, there is no need to open it. In that case only the SSH or VPN port is open, and the VNC connection travels inside it. When you must open the port, restrict it to your IP address.