February 4,2008

用 Wireshark 找出 Cygwin/X 透過VPN之後連線失敗的問題

遇到過底下這個錯誤訊息嗎?把我找到解決方法的經過跟大家分享一下。

XDMCP fatal error: Session failed Session xx failed for display hhh.iii.jjj.kkk:0: Cannot open display.



[前言:安裝、使用 Cygwin/X]
工作上常常需要跟 X Window系統 打交道,但只是最最簡單的操作:使用 Cygwin/X 登入 Solaris(以前還有 HP-UX) 的 CDE 圖形操作介面,再執行我們的應用程式。

(安裝 Cygwin/X 跟安裝 Cygwin 的方法一樣,不過在選擇套件的時候要記得去 "X11" 分類底下多勾選 "xorg-x11-base" 套件。其他相依性套件會自動一併被選取)

裝好之後,妳就可以跟我一樣,在 Cygwin Bash Shell 裡面執行如下的指令:


XWin.exe -query aaa.bbb.ccc.ddd -clipboard &


其中 aaa.bbb.ccc.ddd 是妳要連接的 Unix/Linux 機器,加上 -clipboard 參數才有剪貼簿功能。

我就這樣子用了好幾年。敲指令對我不是大問題,而且我都偷懶,在 Cygwin Bash Shell 裡面打 "history | grep XWin" 列出以前執行過的,然後只要打 !358 (請把358替換成實際上列出來的數字),就可以重複執行該指令。

[問題:Cygwin/X透過VPN之後連線失敗的問題]
我很確定直接連接是沒問題的,但是,如果先登入 VPN ,再試著連接,就會出現類似文章一開始的錯誤訊息:

XDMCP fatal error: Session failed Session xx failed for display hhh.iii.jjj.kkk:0: Cannot open display.


只好祭出自由軟體網路封包嗅探器 Wireshark 來找問題囉。

公益廣告一下,Ethereal已經改名Wireshark了,如果妳的老師/學生/同事還活在2006年,麻煩幫她們的腦袋update一下,感恩。

[不負責小抄:如何在防火牆打洞讓XDMCP可以通過]
(背景:伺服器跑Solaris在 172.18.3.x ,我的筆電透過 3.5G 上網,ip是116.59.28.y,透過checkpoint VPN軟體又取得 ip 172.18.7.z)

基本上英文維基的 X Display Manager Control Protocol 都有解釋了,我們把它重點摘錄:
UDP port 177 要開雙向
TCP port 6000 要開能夠從伺服器通往筆電
用 Wireshark 可以抓到底下這五種 XDMCP 的封包:
Query
Willing
Request
Accept
Manage

XDMCP_Query_Willing_Request_Accept_Manage

這張抓圖的紅框部份是失敗範例,後來我發現是卡在沒有指定 -from 這個參數。

把 XDMCP Request 封包的 "X Display Manager Control Protocol" 小節展開,會看到 Connections 有兩組 ip ,第一組是我上網的 116.59.28.y ,第二組是 VPN 發給我的 172.18.7.z

XDMCP_Request_Connections_TWO_IP

好囉,既然第一組 ip 是來亂的,我們就指定 -from 這個參數,讓 Solaris box 知道它應該跟誰溝通:

XWin.exe -query 172.18.3.x -from 172.18.7.z -clipboard &

XDMCP_Request_Connections_ONE_IP

再用 Wireshark 抓一次,就會看到第一張圖的綠框部份,連接成功!這次把 XDMCP Request 封包的 "X Display Manager Control Protocol" 小節展開,會看到 Connections 只有一組 ip ,是 VPN 發給我的 172.18.7.z

======
不過,X這個通訊協定實在不適合在 VPN 環境下使用,超慢 >_<

======
底下把我寫在 Flickr 的英文版也貼過來:

Cygwin/X usually "just works" for me, until I need to use checkpoint VPN to connect to a Solaris box remotely.

XDMCP fatal error: Session failed Session xx failed for display hhh.iii.jjj.kkk:0: Cannot open display.

I've punched holes on the firewall for UDP 177 bidirectional and TCP 6000 from Solaris to my laptop, still no luck.

So I use Wireshark to check what was actually transmitted down to the packet level.

XDMCP Direct do the following steps: Query, Willing, Request, Accept, Manage. (Thanks to en.wikipedia.org/wiki/X_display_manager )

Turns out I need to specify the local address to connect from when I have multiple NIC on my laptop. The command in Cygwin Bash Shell is like

XWin.exe -query aaa.bbb.ccc.ddd -from ppp.qqq.rrr.sss -clipboard &

aaa.bbb.ccc.ddd being the ip of Solaris box; while ppp.qqq.rrr.sss being the (virtual) ip that was provided to me by checkpoint VPN.

If you have Wireshark, you could expand the "X Display Manager Control Protocol" section of XDMCP Request packet.

In the red box in this screenshot, I had two ip addresses in the "Connections" of the XDMCP Request packet; the 1st being the actual ip address, the 2nd being the virtual ip address that checkpoint VPN gave me. The Solaris box must have been trying/failing to reach my laptop via the 1st, the actual ip address.

After specify the virtual ip address in the command line, in the green box of this screenshot, only one connection(s) in the XDMCP Request packet now, and it worked!

Posted by ystuan at 樂多Roodo! │12:51 │回應(2)引用(0)自由軟體-網路管理
樂多分類:網路/3C 共同主題:自由軟體 工具:編輯本文
標籤:Wireshark
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/5499181
回應文章
改用 NoMachine's NX 吧,相信會滿意許多,而且穿越 VPN 也簡單。
Posted by jserv at February 4,2008 22:38

jserv,

嗯,我當時內心的OS也是說:如果有 FreeNX 或者 NoMachine NX 就好了!

不過,需要一台機器來裝 FreeNX 或是 NoMachine NX ,當作跳板。最省硬體經費的方式,是從那些 Solaris 機器挑一台出來當跳板。

這樣的好處是不用生機器,壞處是拿原本上線運轉的系統來兼做 IT infrastructure 。

我是覺得上線的系統跟 IT 用來遠端管理的機器應該切開比較好,不過這樣就需要$$買硬體了。

錢還是小事,買台 PC 灌 Linux 我花點時間就可以搞定(以前在另一個客戶那邊用過 FreeNX)。不過在我們這個行業的客戶啊,「設備放進機櫃」的申請手續,對我來說可能才是關卡呢。
Posted by PowerOp at February 5,2008 12:53