Bài này sẻ mô phỏng: Máy Server là Centos, Client là Windows XP
Bước 1: Enable Remote Desktop trên Server:
Vào System/Preferences/Remote Desktop. Đánh dấu chọn vào Allow other users to view your desktop và Require the users to enter this password -> sau đó nhập password vào
Bước 2: Kiểm tra xem VNCserver đã cài chưa:
$ rpm -qa | grep vnc vnc-server-4.1.2-23.fc8 vnc-4.1.2-23.fc8
Nếu chưa cài ta dùng lệnh:
#yum install vnc-server
Bước 3: Cài X Windows System (KDE và GNOME Desktop Environement !)
Kiểm tra xem cài chưa:
[#]yum grouplist
Nếu chưa cài:
yum groupinstall “X Window System” “GNOME Desktop Environment”
Sau khi cài đặt xong GNOME Desktop Environnement,chúng ta chuyển qua KDE chạy lệnh :
yum groupinstall “X Window System” “GNOME Desktop Environment”
Bước 4: Hiệu chỉnh config của VNC Server
vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# 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
# . # Use “-nolisten tcp” to prevent X connections to your VNC server via TCP.
# Use “-nohttpd” to prevent web-based VNC clients connecting.
# Use “-localhost” to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the “-via” option in the
# `man vncviewer’ manual page.
VNCSERVERS=”1:root”
VNCSERVERARGS[1]=”-geometry 800×600″
Dòng VNCSERVERS=”1:quanta” sẽ sets up một user cho vnc server, bạn có thể thêm bao nhiêu users tuỳ ý.
Dòng VNCSERVERARGS[1] set các tham số cho user 1
Chú ý rằng: session number user cũng nói cho chúng ta biết cổng mà vncserver sẽ lắng nghe. Nhớ rằng, Gnome Remote Desktop hỏi chúng ta để sử dụng computername:0 như một chuỗi kết nối, session number sẽ được cộng thêm 5900 để ra cổng mà vncserver sẽ lắng nghe. Trong trường hợp này chúng ta cần sử dụng cổng 5901, nên chúng ta dùng session 1. Bạn có thể sử dụng bất kỳ số nào, ví dụ:
VNCSERVERS=”2000:bobpeers”
VNCSERVERARGS[2000]=”-geometry 1024×768 -depth 16″
Lúc này thì chúng ta phải dùng cổng 7900
ESC để thoát Insert Mode,rồi dùng lệnh :wq,để save file đó lại và trở về command của SSH !
Bước 5: Khởi động VNC Server và đặt password nhằm tăng mức đọ bảo mật:
vncserver
Bước 6: Sửa file xstartup
vi /root/.vnc/xstartup
Bỏ 2 dấu thăngs ở 2 đoạn như code dưới :
#!/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 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
twm &
Bấm :wq và thoát
Bước 7: Khởi động lại VNCServer:
/etc/init.d/vncserver restart
Bước 8: Tắt filewall:
/etc/init.d/iptables stop
Bước 9: Download VNC CLient về trên máy client Windows XP tại địa chỉ: [Chỉ có thành viên mới thấy links này. ]
Bật VNC Client , nhập IP SVR theo dạng
IP:1 hoac IP:2 do bạnconfig trong files /etc/sysconfig/vncservers
Lưu ý: Muốn kết nối từ xa, đi ra ngoài wan thì ta cần làm thêm những bước sau:
Add port
System -> administration -> Firewall and Linux -> chọn Firewall Options tab
-> Other ports -> Add button, nhập 5901 với giao thức là tcp -> OK
Chỉnh sửa iptables để mở cổng
$ sudo vim /etc/sysconfig/iptables
-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 -p udp –dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 631 -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 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 2049 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 137 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 138 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 139 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 445 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 23 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5901 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT
Restart lại iptables service
Code:
$ 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 ] Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]
Cuối cùng, các bạn nhớ NAT port 5901 trên modem và bật vncclient lên kết nối nhé.