[b]什么是VNC?[/b]
VNC是虛擬網絡計算Virtual Network Computing的縮寫. 他是一個遠程控制程序,允許用戶在因特網的任何地方使用簡單的程序來和一個特定的
計算機(服務器)進行交互. 兩個交互的計算機不一定非得是同一類型,所以你可以在家里的運行windows的PC上來察看辦公室里運行LINUX的機器
。VNC可以自由獲取并且有上百萬的人在使用,他們來自工業、學術和個人應用等不同層面.
更多的信息請訪問 [url]http://www.realvnc.com/[/url]
[b]我的系統中已經有這個軟件了嗎?[/b]
鍵入下面的命令來檢查vnc客戶端和服務器是否已經安裝在你的系統中:
[tchung@tchung101 tchung]$ rpm -q vnc vnc-server
vnc-4.0-0.beta4.3.2
vnc-server-4.0-0.beta4.3.2
[tchung@tchung101 tchung]$
要把vnc配置成一項系統服務,把你的用戶名稱加入到下面的配置文件中:
[code][tchung@tchung101 tchung]$ sudo vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# as my 'myusername' (adjust this to your own).??You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!??For a secure way of using VNC, see
# URL:http://www.uk.research.att.com/vnc/sshvnc.html
? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?
# VNCSERVERS="1:myusername"
VNCSERVERS="1:tchung"[/code]
在啟動vnc服務之前,讓我們用vncpasswd這個命令來創建一個vnc的口令
注意這將同時在你的home目錄下,創建一個隱藏的目錄.vnc,其中有一個文件passwd保存著你的vnc口令.
[code][tchung@tchung101 tchung]$ vncpasswd
Password:
Verify:
[tchung@tchung101 tchung]$ ls -d .vnc
.vnc
[tchung@tchung101 tchung]$ ls .vnc
passwd
[tchung@tchung101 tchung]$[/code]
現在來啟動vnc服務.
[code][tchung@tchung101 tchung]$ sudo /sbin/service vncserver start
Starting VNC server: 1:tchung? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?[??OK??]
[tchung@tchung101 tchung]$[/code]
察看一下.vnc這個目錄的內容,應該類似于下面的東西.
[code][tchung@tchung101 tchung]$ cd .vnc
[tchung@tchung101 .vnc]$ ls
passwd??tchung101:1.log??tchung101:1.pid??xstartup
[tchung@tchung101 .vnc]$[/code]
編輯這個名為xstartup的腳本,注意到下面紅色的部分的注釋
將這兩行標記成[color=red]紅色[/color]的內容前面的注釋符號去掉,否則你將只能得到一個什么都沒有的灰屏。#!/bin/sh
? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?
# Uncomment the following two lines for normal desktop:
[color=red]unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc[/color]
? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?
[ -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 &
因為我們已經修改了啟動腳本,現在來重新啟動vncserver.
[code][tchung@tchung101 tchung]$ sudo /sbin/service vncserver restart
Shutting down VNC server: 1:tchung? ?? ?? ?? ?? ?? ?? ?? ? [??OK??]
Starting VNC server: 1:tchung? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?[??OK??]
[tchung@tchung101 tchung]$[/code]
那么怎樣來連接到vncserver? 照下面使用客戶端的vncviewer命令.
[tchung@tchung101 tchung]$ vncviewer localhost:1
輸入你的vnc口令,看一下結果
更新:
在使用防火墻的情況下來連接到一個遠程系統,需要打開端口5901.
加入以下紅色的部分,然后重啟iptables服務。
[tchung@tchung101 tchung]$ sudo vi /etc/sysconfig/iptables
# Firewall configuration written by redhat-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0]
:FORWARD ACCEPT [0]
:OUTPUT ACCEPT [0]
:RH-Firewall-1-INPUT - [0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
[color=red]-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT[/color]
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
[tchung@tchung101 tchung]$ sudo /sbin/service iptables restart
Flushing firewall rules:? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???[??OK??]
Setting chains to policy ACCEPT: filter? ?? ?? ?? ?? ?? ???[??OK??]
Unloading iptables modules:? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???[??OK??]
Applying iptables firewall rules:? ?? ?? ?? ?? ?? ?? ?? ???[??OK??]
[tchung@tchung101 tchung]$
Forrest Taylor 提供的TIP
讓vncserver接受兩個不同的用戶:
? ?[code] VNCSERVERS="1:tchung 2:thomasc"[/code]
當然你要為兩個用戶分別運行vncpasswd來設置口令. 并且在你的防火墻修改中,你應該明白VNC使用端口5901給連接1用,如果象上面一樣要支
持兩個用戶,應同時打開5901和5902.