Ova

How to Change the Port Number on Your Raspberry Pi VNC?

Published in Raspberry Pi VNC Port 4 mins read

To change the VNC port number on your Raspberry Pi, you need to adjust the settings within the VNC Server application on the Pi itself. This process typically involves accessing the VNC server options through its taskbar icon.

Steps to Modify Your VNC Port

Changing the VNC port ensures your connection doesn't conflict with other services or allows for enhanced security by using a non-standard port. Follow these straightforward steps:

  1. Locate the VNC Icon: On your Raspberry Pi's desktop, find the VNC Server icon, usually in the taskbar or system tray (often looks like a black square with a white 'V').
  2. Access Options: Right-click on the VNC Server icon to open its context menu. Select "Options" from the menu.
  3. Navigate to Connections: In the VNC Server Options window, click on the "Connections" tab or page.
  4. Set the Port Number: Look for the "Port number" setting, which is typically located at the top right of the Connections page, often on the same line as the "Allow VNC connections over TCP" checkbox. Enter your desired new port number here. Common VNC ports start from 5900, with 5900 being display :0, 5901 for display :1, and so on. You can choose a port outside this range, but ensure it's not already in use by another service (e.g., HTTP on 80, HTTPS on 443, SSH on 22).
  5. Apply Changes: Click "OK" or "Apply" to save your new port setting. The VNC server will now listen for incoming connections on this new port.

Connecting to the New Port

Once you've changed the port on your Raspberry Pi, your VNC Viewer application (on your client device like a PC, Mac, or smartphone) must specify this new port to connect successfully.

  • When you enter the Raspberry Pi's IP address or hostname in your VNC Viewer, you'll need to add a colon (:) followed by the new port number at the end of the address.

    • Example: If your Raspberry Pi's IP address is 192.168.1.100 and you changed the VNC port to 5905, you would enter 192.168.1.100:5905 into your VNC Viewer.
    • Example with hostname: If your Raspberry Pi's hostname is raspberrypi.local and the port is 5905, you would enter raspberrypi.local:5905.

Understanding VNC Port Numbers

VNC uses a system of display numbers that correspond to specific port numbers. The default VNC port is 5900 for display :0. Each subsequent display number increments the port by one.

Display Number Default Port Description
:0 5900 Primary desktop display
:1 5901 Secondary display or a virtual session
:2 5902 Third display or another virtual session
... ... And so on for additional VNC sessions

Why Change the Default VNC Port?

There are several compelling reasons to consider moving away from the default VNC port (5900):

  • Security Through Obscurity: While not a primary security measure, using a non-standard port can reduce automated scanning attempts by bots looking for default VNC services.
  • Avoiding Conflicts: If you have other services running on your network that might use ports in the 5900 range, changing the VNC port prevents conflicts.
  • Firewall Configuration: Some network environments might have firewalls that block common VNC ports. Using a different port might simplify firewall rules in specific scenarios (though you'd still need to open the new port).
  • Multiple VNC Servers: If you run multiple VNC servers on different machines within the same local network, or even multiple VNC sessions on a single machine, assigning unique ports is essential.

Important Considerations

  • Firewall Rules: If your Raspberry Pi is behind a firewall (either on the Pi itself or your network router), you must ensure the new port you've chosen is open to allow incoming connections. For external access, you'll also need to configure port forwarding on your router. For more information on this, consult the Raspberry Pi documentation or your router's manual.
  • Port Range: Choose a port number that is generally not used by common services. Ports above 1023 are often suitable, with ports above 49151 generally designated as "dynamic/private ports."
  • VNC Server Type: The exact menu options might vary slightly depending on the specific VNC server software you have installed (e.g., RealVNC, TightVNC). However, the general principle of finding the "Options" or "Settings" and then a "Connections" tab holds true for most. RealVNC Connect, which is often pre-installed on Raspberry Pi OS, follows the described steps closely.

By following these instructions, you can easily customize your VNC connection, enhancing security and flexibility for remote access to your Raspberry Pi.