---
title: "Using tsclient of Ubuntu to connect to Centos via vnc protocol"
author: "lasol"
date: "2011-06-28T09:38:49Z"
tags: []
categories: ["操作系统"]
slug: "using-tsclient-of-ubuntu-to-connect-to-centos-via-vnc-protocol"
draft: false
lastmod: "2011-06-28T09:38:49Z"
id: 1107273
url: "https://lasol.iteye.com/blog/1107273"
---

environment:  
Server: CentOS 5.6 64bit  
Client: Ubuntu 11.04 64bit  
TOOL:terminal server client  
protocol:vnc

Server Part:

1、Check if vnc server is installed.  
\[root@localhost ~]# rpm -qa|grep vnc  
vnc-server-4.1.2-14.el5\_6.6  
gtk-vnc-0.3.8-3.el5  
gtk-vnc-python-0.3.8-3.el5

If not,install it.  
From source:  
#yum install vnc-server*

From disc:  
#rpm -ivh vnc*

2、configure your vnc server  
#vi /root/.vnc/xstartup  
remove the comment before line 'unset SESSION\_MANAGER' & line 'exec /etc/X11/xinit/xinitrc';  
Add a line 'gnome-session';  
the whole file as follow:  
#!/bin/sh

\# Uncomment the following two lines for normal desktop:  
unset SESSION\_MANAGER  
exec /etc/X11/xinit/xinitrc

\[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup  
\[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources  
xsetroot -solid grey  
vncconfig -iconic &  
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &  
#twm &  
gnome-session

 

#vncserver

to set the passwd

 

3、configure your vncservers file

#vi /etc/sysconfig/vncservers

Add following lines:

VNCSERVERS="1:oracle "  
VNCSERVERARGS\[1 ]="-geometry 1024x768"

VNCSERVERS="2:root "  
VNCSERVERARGS\[2 ]="-geometry 1024x768"

 

##tip: Every user can start more than one server; when vnc server is started, A sequence number is

assigned to the connection, such as xxx.xxx.xxx.xxx:1; When configure vncservers file , the number

should match the user.

 

Restart your vnc server

#/etc/init.d/vncserver restart

 

4、configure the firewall

##tip:the begining port to support vnc server service is 5901 and 5901 is for screen 1,5902 for screen 2 and so on

 

#vi /etc/sysconfig/iptables

ADD:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT

 

Restart your firewall

#/etc/init.d/iptables restart

 

Your VNC server is working now.

 

Client Part:

 

It's easy for client part, make sure you can connect to your vnc server via ssh tunnel.

To check if you can connect to the right port:

$ telnet XXX.XXX.XXX.XXX 5901

If you see:

Trying XXX.XXX.XXX.XXX...  
Connected to XXX.XXX.XXX.XXX.  
Escape character is '^]'.  
RFB 003.008  
then the port 5901 is open. you can connect the vnc server.

If not, you should check your ssh connection.

Try:$ssh root@XXX.XXX.XXX.XXX to login.

 

$sudo apt-get install vncviewer

start your tsclient;

fill the computer name using :xxx.xxx.xxx.xxx:1

fill the protocol:vnc

fill the user name: remote server's user name (should match the screen no.)

 

OK，it works.