VNC (Virtual Network Computing)

VNC (Virtual Network Computing)


What is VNC and how does it work?

VNC (Virtual Network Computing) is a technology that allows you to control a remote computer over a network, typically the internet, as if you were physically sitting in front of it. It enables remote desktop sharing and control (You can think of it as something similar to Team Viewer or Any Desk Apps). Here's a simplified explanation of how VNC works:

  • Server and Client: VNC consists of two components – the VNC server and the VNC client. The remote computer you want to control runs the VNC server, while the computer you're using to control the remote computer runs the VNC client.
  • Server Initialization: On the remote computer, you install and configure a VNC server software. When you start this server, it listens for incoming connections on a specific port (usually 5900 by default). and if the remote computer reboots, the VNC server service will start again automatically.
  • Client Initialization: On your local computer, you install a VNC client software. This software allows you to connect to the remote server. When you launch the VNC client, you specify the IP address or hostname of the remote computer and the port number to connect to (usually in the format "hostname:port").
  • Handshake and Authentication: Once you initiate a connection, the VNC client and server perform a handshake to establish communication. Depending on the VNC server's configuration, you may be prompted to enter a password or use other authentication methods to prove your identity and gain access to the remote computer.
  • Screen Sharing: After successful authentication, the VNC client sends your input (keyboard and mouse actions) to the remote VNC server. The server processes these inputs and updates the screen accordingly. This process is bidirectional, meaning the VNC server also sends back the remote desktop's screen data to the VNC client so you can see what's happening on the remote computer.
  • Data Compression and Optimization: To make the remote desktop experience smoother, VNC often employs data compression techniques to minimize the amount of data sent over the network. It also optimizes screen updates to reduce bandwidth usage and improve performance.
  • Session Termination: When you're done using the remote computer, you can either disconnect or log out from the VNC session. The VNC server may continue to run in the background on the remote computer, waiting for the next connection request.

There are different implementations and variations of VNC, such as TightVNC, RealVNC, X11VNC, Tiger VNC and UltraVNC, each with its own features and capabilities.

It's important to note that while VNC provides remote access and control, security considerations are crucial. Using strong passwords, encryption, and configuring firewalls properly is essential to protect the remote computer and data during VNC sessions, especially when accessing remote computers over the internet.

Installing VNC Server on remote computer and login to it!

Enough theory? let's try to make things more interesting by demonstrating how you can control remote computer using VNC.

In my case, I want to control remote computer (Ubuntu Desktop LTS 22.0) running somewhere in the cloud from my windows 11 laptop. So I need to do the following:

  1. Install VNC Server on my remote Ubuntu machine (I will use open source X11 VNC Server)

sudo apt-get update 
// (This is to update our references)
sudo apt-get install lightdm 
// (This changes the display manager)
sudo reboot

sudo apt-get install x11vnc
sudo nano /lib/systemd/system/x11vnc.service 
//let's configure the service, copy and paste the code below and change the "password" to your own password:

[Unit]
Description=x11vnc service
After=display-manager.service network.target syslog.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -forever -display :0 -auth guess -passwd password
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure

[Install]
WantedBy=multi-user.target

//CTRL+O to save , then CTRL+X to exit

sudo systemctl daemon reload
//restart the service

sudo systemctl enable x11vnc.service
//enable the x11vnc service

sudo systemctl start x11vnc.service
//start the VNC Server service "x11vnc.service"

sudo systemctl status x11vnc.service
//to check if the VNC server service has been started, you should see an output saying that service is active (running), then CTRL+C to back to CLI        
typically, you need to disable screen lock for the remote computer you are trying to manage, because if the screen lock is enabled, after defined period of time this will lock the screen and might causing issues for the VNC when you try to connect to it.

  1. Install VNC Viewer on my windows 11 laptop, this will enable me to connect to the VNC server running on the remote Ubuntu VM (I will use free version of RealVNC viewer). You can download RealVNC viewer from this link. and follow typical windows application installation process, then you will end up with screen like this:

Real VNC Viewer application for windows


your application window will be empty with no hosts added if this is your first time using Real VNC viewer, but in a moment, we are going to your first machine.

Click on File, then New connection, and you will have the following window open:

adding new host to Real VNC Viewer

Type the IP address of your remote machine, of course you must have connectivity to the remote host over the internet, LAN, or VPN. and give it friendly name so you can remember 1 year later what this host was xD.

you will be prompted to enter the password, remember this is the password you set earlier in step 1 above when configuring the x11vnc.service file!

  1. Finally, you have the host being added and all what you need to do is to double click on the host and voila !! you have access to this remote computer as you are sitting in front of it.

controlling remote ubuntu desktop by VNC

Few important note!

  1. as you are accessing your remote computer over the network, security is crucial here, you need to make sure that the traffic between the VNC client (your local computer) and the VNC server (your remote computer) is encrypted.
  2. the default port for VNC is 5900, but it depends on the implementation you decide to use, so it worth checking what port is actually being used. and allow the traffic for this port through your firewalls if there are any.

by default, in Ubuntu Desktop LTS 22.04 version, UFW (Uncomplicated Firewall) is off, but there is no harm in double checking that if you find yourself troubleshooting the connection and make rule to allow traffic destined to port 5900 or whatever port is being used by your VNC server.

  1. Copy and Paste, this sound silly but by default most VNC implementations does not support copy and paste in the free tier, at least this is what I found so you need to spend some time in making that work by looking over the Internet.
  2. File Sharing from your local computer to the remote computer is a feature that is normally you can find in the paid version of VNC implementations, within the next few days I will look for free open source VNC implementation that support file sharing and copy and paste.

So, this is it, I hope this helped you and see you in another article.




Glad to see more people are using Ubuntu nowadays!

Atheer Muhammed

IP Network | 2X CCNP SP & EI | NSE4 | MTCRE-MTCNA @ X company

1 年

actually useful article for network engineers ??

回复

要查看或添加评论,请登录

Karam Al Shukur的更多文章

  • How to renew your Cisco Certification for FREE!

    How to renew your Cisco Certification for FREE!

    Verify your current certification status Once you pass any Cisco certification exam, you generally have three years to…

    3 条评论

社区洞察

其他会员也浏览了