LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1613|回复: 10

MSN音视频聊天如何穿透linux网关?

[复制链接]
发表于 2006-4-5 18:18:05 | 显示全部楼层 |阅读模式
包括这个论坛,查找了半天,没找到清楚的做法,看到的有:
1 安装upnp和libigd,利用msn client支持的upnp协议穿透网关.
2 iptables开放udp和相关端口,这个似乎不可行?
3 网关上开socks代理,msn client通过socks代理穿透网关?
请求高人给解.
发表于 2006-4-5 19:41:30 | 显示全部楼层
$IPTABLES -N msn_packets
$IPTABLES -A msn_packets -p TCP --dport 6891:6900 -m state --state NEW -j ACCEPT
$IPTABLES -A msn_packets -p TCP --dport 1863 -m state --state NEW -j ACCEPT
$IPTABLES -A msn_packets -p TCP --dport 6901 -m state --state NEW -j ACCEPT
$IPTABLES -A msn_packets -p UDP --dport 1863 -j ACCEPT
$IPTABLES -A msn_packets -p UDP --dport 5190 -j ACCEPT
$IPTABLES -A msn_packets -p UDP --dport 6901 -j ACCEPT

我没用过,但是这个是我在网上看到,针对MSN的规则。

补充遗漏的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-6 09:15:40 | 显示全部楼层
iptables -A msn_packets -p TCP --dport 6891:6900 -m state --state NEW -j ACCEPT
iptables: No chain/target/match by that name
回复 支持 反对

使用道具 举报

发表于 2006-4-6 09:56:07 | 显示全部楼层
你看到的肯定只是一个脚本片段,应该还有关于创建新的chain的和将相应的IP数据流导入这个chain的脚本片段你没有贴出来。
回复 支持 反对

使用道具 举报

发表于 2006-4-6 11:09:04 | 显示全部楼层
msn_packets 能到里面去麽?
回复 支持 反对

使用道具 举报

发表于 2006-4-6 19:22:49 | 显示全部楼层
Post by springwind426
你看到的肯定只是一个脚本片段,应该还有关于创建新的chain的和将相应的IP数据流导入这个chain的脚本片段你没有贴出来。


已经补充了新建的那个语句。。。。

至于导入语句,我没有用过,所以也无法提供。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-7 08:42:21 | 显示全部楼层
有一篇用法语写的wiki描述这个问题,经过google translate如下,可作参考:
The theory: which is the problem?
[ to modify ]
Setting in situation

Let us take following topology: you use at the house your PC under Windows, with MSN Messenger to discuss with your friends, and more particularly for the transfer transfer functions of files, vocal and video cat. We will call this PC: XP1 .
Another PC in the house is used same manner, under Windows, and is used occasionally for messenger: we will call it XP2 .
Lastly, all this beautiful world is connected to Internet via a fire wall/Linux router which shares its connection ADSL: we will call it Nunux.
[ to modify ]
Simple case

When you chattez on XP1 (cat msn text), msn will be connected on port 1863/TCP to a waiter from microsoft. Nunux thus knows that it is XP1 which initiated connection towards the waiter at ms, and will thus know router the packages that the latter will return in answer.
Idem, if XP2 is useful comes to connect same manner, Nunux will be able to track (English tracker) connection, not to mix flows all this functions extremely well, it acts of traditional NAT (Network Address Translation).
[ to modify ]
Encountered problems

The problems arrive when you ask for a vocal/video connection. In this case, msn will require of the waiter to choose another port to make pass video flow. And the problem it is that this port is selected randomly between port TCP/9000 and TCP/65535!
Then, comes the moment from connection itself, and it is there that the firewall loses the pedals, not knowing more where router the requests which arrive to him, on ports which leave nowhere, etc...
[ to modify ]
Presentation of the solution

The solution adopted by industry is upnp: it is the application itself which requires, dynamically, to the firewall to open the selected port (randomly I point out it to you), and to return towards machine MSN (XP1 in this example) video/audio flow. Then connection goes. However, iptables cannot manage that out of standard.

One of the solutions consists with all to return directly towards PC MSN. In this case, Ca goes, not need for upnp... in condition however which you have one customer MSN behind! If not the firewall will not know towards which to return flow.

The only clean and elegant solution: to install upnp. Many are those which regard upnp as an aberration level safety. For my part I find the system rather elegant: the requests for opening of port can come only from the interior of the local area network. Thus to open a breach to allow an attack would require to have an in-house accomplice, to agree in advance on the port on which one will attack, which in my case, is incredible, and the comfort brought by the use of upnp largely exceeds this risk which I consider tiny.

On this, follow the guide!
[ to modify ]
My configuration network

My Gentoo is on my footbridge/fire wall. It is configured with a modem speedtouch usb. My IP public thus corresponds to the interface ppp0. My network internal, him, is configured on eth0.

My PC of test is under Windows, classically.

Firewall question, I have few things: I activated the NAT in the file /etc/conf.d/iptables by validating the following line:
File:

ENABLE_FORWARDING_IPv4="yes "

And here the code of my firewall, which filters only NETBIOS in fact:
Code: rudimentary filtering

    # flush of the firewall:

iptables - F iptables - F - T nat

    # activation of the NAT:

iptables - T nat - A POSTROUTING - J MASQUERADE - O ppp0

    # DROP of packages NETBIOS

iptables - A INPUT - I ppp0 - p UDP -- dport 137:139 - J DROP iptables - A INPUT - I ppp0 - p TCP -- dport 137:139 - J DROP

As I said it to you: a rudimentary filtering, I want a minimum of obstacles when I work.
[ to modify ]
The installation of the tools upnp for GNU/Linux.

The demon upnp for linux names... upnpd. Enough discussed, it has nevertheless the merit to exist, and I will thus quote what the developers say on this page :

The developers of upnpd wrote:

        There are many opponents against UPnP. However, we feel that Open Source is all butt giving people choices, and letting intelligent people make intelligent decisions butt its uses. With batch of custom really NEED this daemon, and edge live with the consequences because we are simply connecting has home network to the Internet through one IP, and we would cuts had the Windows machines (gold whatever Internet device) connected directly in the first place.

To date (July 18, 2005), the development of linux-igd ( Internet Gateway Device , the package which contains upnpd) is almost stopped. According to its author, one should not moreover not use the last version of the package upnp (the 1.2.1a) but a older version (1.0.4). It is necessary thus to mask the new version (only if you are in ~x86; if you are in x86 it is not worth while bus upnp-1.2.1a is marked unstable ).
Code: Masking of the new version of upnp

echo = Net-misc/upnp-1.2.1a > >/etc/portage/package.mask

On the other hand it is to better use the very last version of linux-igd:
Code: Use of the unstable version of linux-igd

echo Net-misc/linux-igd ~x86 > >/etc/portage/package.keywords

Then launch the installation
Code: Installation of linux-igd

emerge linux-igd

Then, do not forget to configure your interfaces in the file /etc/linuxigd/upnpd.conf . For my configuration, that gives:
File:

# configuration spins for upnpd INTERFACE="eth0 "OUTERFACE="ppp0"

Lastly, before launching the demon, a last stage: add the following line in your file /etc/conf.d/local.start , then launch it directly in the line of order. Do not forget to adapt to your config (eth0 is not inevitably your internal interface)!
File:

road add - Net 239.0.0.0 netmask 255.0.0.0 eth0

If you configured iptables as a firewall, it is necessary to activate the access to the demon upnp, without what it will not be used for nothing since nobody will be able nothing to ask him: -)

This access is done by protocol HTTP on port TCP/2869 (posted in/etc/linux-igd/gatedesc.xml in the URLBase beacon). It is thus necessary to open this port for the access by the local interface (here eth0):
Code: Configuration of the fire wall

iptables - A INPUT - I eth0 - p TCP -- dport 2869 - J ACCEPT

Here, it is finished: you can now start the demon:
Code: Starting of the demon

/etc/init.d/upnpd start

And even to program it for each starting (useful if you hope to use it regularly, not to have to launch it to each conversation msn):
Code: Automation of the launching of the demon

rc-update add upnpd default

[ to modify ]
Test!

Here, in theory at this stage you can use the function webcam, and the file transfer from a station behind your router/fire wall linux.

If you use a software of peer 2 peer compatible UPnP (like Azureus or follower Morph XT), think of activating this functionality: it will render much service to you (for example to have HighID with follower).

In a friendly way.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-7 08:58:43 | 显示全部楼层
作者:
dagger
无崖阁
xyg.ods.org

版本:
1.0        2003-06-22
        初始版本

一、引言
目前Linux的NAT和firewall只支持MSN Messenger的文字聊天,
本文介绍了如何让Linux的NAT和firewall支持MSN Messenger的语音聊天、文件传送等其它功能的方法。

二、几个基本概念
1、Linux NAT
Network Address Translation (NAT)是IETF的一个标准,用来使在私有网络中的PC和设备共享一个公开的可路由的IPv4地址。
使用NAT的一个主要原因是缓解目前IPv4地址资源的不足。通常NAT被用在网关设备中,位于私有网络和公共Internet之间。
当IP包要通过网关时,NAT就会把私有IP地址、端口和公开的IP地址、端口作转换。
Linux 2.4内核中NAT分为两种,Source NAT (SNAT)和Destination NAT (DNAT)。Source NAT就是转换IP包头的源地址,
SNAT总是在POSTROUTING中处理,即包被发送出去之前。Masquerading(IP伪装)是SNAT的一种特殊形式。
Destination NAT就是转换IP包头的目的地址,DNAT总是在PREROUTING中处理,即在收到包后在路由处理之前。
Port forwarding、load sharing、和transparent proxying都是属于DNAT。
Linux 2.4内核的NAT流程图:
             _____                                     _____
            /     \                                   /     \
          PREROUTING -->[Routing ]----------------->OSTROUTING----->
            \D-NAT/     [Decision]                    \S-NAT/
                            |                            ^
                            |                            |
                            |                            |
                            |                            |
                            |                            |
                            |                            |
                            |                            |
                            --------> Local Process ------

2、Linux Packet Filter
在Linux中使用包过滤(Packet Filter)来实现防火墙(firewall)的功能。Linux在内核中检查通过的包头,
决定所有包的命运,可能是丢弃(DROP)这个包,或允许(ACCEPT)包通过,或其它更复杂的动作。使用包过滤主要可以实现控制、
安全和警戒的功能。Linux 2.4内核中有三个过滤规则表,它们是INPUT、FORWARD和OUTPUT。对于数据包,如果是发给本机的,
则交INPUT处理;如果是发给其它PC或设备的,则交FORWARD处理;如果是由本机发送的,则交OUTPUT处理。
Linux 2.4内核的Packet Filter流程图:
                            _____
  Incoming                 /     \         Outgoing
         -->[Routing ]--->|FORWARD|------->
            [Decision]     \_____/        ^
                 |                        |
                 v                       ____
                ___                     /    \
               /   \                   |OUTPUT|
              |INPUT|                   \____/
               \___/                      ^
                 |                        |
                  ----> Local Process ----


3、UPnP
Universal Plug and Play (UPnP)是一种架构,用来实现目前流行的PC、智能设备或装置(特别是家庭中的)的端到端的网络连接。
UPnP基于Internet标准和技术,如TCP/IP、HTTP和XML,支持“零配置”网络和自动发现,一个设备可以动态地加入一个网络,
获得一个IP地址,声明自己的名字,向其它设备回应自己的能力,并学习到网络中其它设备的存在和能力。进一步,
一个设备可以平滑地并自动地离开这个网络,不会留下任何不期望保存的状态。UPnP会集了多个厂商的合作,以建立标准的
Device Control Protocols (DCPs),使用XML来表达,通过HTTP来通信,并提出了Internet Gateway Device (IGD)规格。

4、MSN Messenger使用的端口
微软的MSN Messenger软件是流行的即时通行软件,包含很多功能,根据微软的资料这个软件需要使用很多端口。
文字聊天:TCP 1863或80
音频和视频聊天:UDP 5004-65535 动态分配
应用共享和白板:TCP 1503
文件传输:TCP 6891-6900 允许一次传10个文件
远程助手:TCP 3389

三、遇到的问题
目前我这里的环境是在网关的计算机上装了Redhat Linux 8.0,配置了Masquerading可以让内部网络中的计算机共享上网;
配置了firewall限制外部计算机对网关的部分端口的访问。内部网络中的计算机除了MSN Messenger的文字聊天可以正常与外界通信外,
其它如音频聊天、文件传输等功能都无法实现。
NAT的问题:
* 在NAT后面的计算机使用私有IP地址,MSN Messenger会把这个私有IP地址的数据传送给对端,而NAT只能转换IP包头的内容,
无法转换IP包数据中包含的私有地址。
* NAT需要Port forwarding (端口映射)来使外部IP地址和端口与内部计算机IP地址与端口对应。MSN Messenger动态使用端口,
需要NAT能动态端口映射。
* 对于使用静态端口的情况,在NAT后面只能有一台计算机使用此功能。
firewall的问题:
* 对应MSN Messenger的TCP和UDP端口不能禁止,需要都开放。

四、解决方法
1、方案
MSN Messenger使用了UPnP,我们只要在Linux网关中支持UPnP,就能让MSN Messenger实现自动获得相应的NAT或firewall信息,
从而可以使用正确的IP地址和端口来通信。
目前已经有Linux下的UPnP开发包(libupnp)和支持Internet Gateway Device规格的应用软件(linux-igd)。

2、获得软件包
libupnp-1.2.1.tar.gz
http://sourceforge.net/projects/upnp
linuxigd-0.92.tgz
http://sourceforge.net/projects/linux-igd

3、编译安装
由于linuxigd-0.92原来是基于1.0.4版的UPnP开发包开发的,所以需要适当改动以支持最新的1.2.1版UPnP开发包。
(1) 编译安装libupnp
tar xzvf libupnp-1.2.1.tar.gz
cd libupnp-1.2.1/upnp/
make DEBUG=1 WEB=0
make install
安装后UPnP开发包的头文件就安装在/usr/include/upnp目录下,库文件就安装在/usr/lib目录下。

(2) 编译安装linuxigd
tar xzvf linuxigd-0.92.tgz
cd linux-igd/
cp ../libupnp-1.2.1/upnp/sample/common/sample_util.c sample_util.cpp
cp ../libupnp-1.2.1/upnp/sample/common/sample_util.h sample_util.h
并修改sample_utils.cpp文件:
把第661行的
*controlURL =
替换为
*controlURL = (char *)
把第671行的
*eventURL =
替换为
*eventURL = (char *)

修改gateway.h文件:
把第29行的
#define INIT_PORT          2869
替换为
#define INIT_PORT          52869

修改gate.cpp文件:
在第34行插入3行
#define UpnpDocument_free ixmlDocument_free
#define UpnpParse_Buffer ixmlParseBuffer
typedef IXML_Document *Upnp_Document;

链接头文件目录:
ln -s ../libupnp-1.2.1/upnp/inc upnp
并修改gate.h文件:
把第27行的
#include
替换为
#include "upnp/upnp.h"

修改gateway.cpp文件:
把第36行的
#include
替换为
#include "upnp/upnp.h"

修改sample_util.h文件:
把第43行的
#include "upnptools.h"
替换为
#include "upnp/upnptools.h"

再修改Makefile文件:
把第3行的
LIBS= -lpthread  /usr/lib/libupnp.so
替换为
LIBS= -lpthread -lupnp

以上都修改完后,执行make,make install
安装后执行文件在/usr/bin目录下,配置文件在/etc/linuxigd目录下。

4、配置运行
添加一条路由:
route add -net 239.0.0.0 netmask 255.0.0.0 eth1
这里eth1是连接内部网络的网卡。
在/usr/sbin目录下添加iptables的符号连接:
ln -s /sbin/iptables /usr/sbin/iptables
因为linux-igd使用/usr/sbin/iptables,而Redhat Linux 8.0的iptables在/sbin目录下。
启动linux-igd:
upnpd eth0 eth1
这里eth0是连接Internet的网卡。
upnpd的debug信息输出在/var/log/debug文件中,如果你的系统上没有这个文件,可以编辑/etc/syslog.conf文件,加入:
*.debug                /var/log/debug
并重新启动syslogd就可以了。

5、功能测试
upnpd程序正常启动后,我们可以在/var/log/debug文件中看到如下信息:
Jun 15 17:49:43 svr upnpd: The Linux UPnP Internet Gateway Device Ver 0.92 by Dime (dime@gulfsales.com)
Jun 15 17:49:43 svr upnpd: Special Thanks for Intel's Open Source SDK and original author Genmei Mori's work.
Jun 15 17:49:43 svr upnpd: Intializing UPnP with desc_doc_url=http://192.168.0.1:52869/gatedesc.xml
Jun 15 17:49:43 svr upnpd: ipaddress=192.168.0.1 port=52869
Jun 15 17:49:43 svr upnpd: conf_dir_path=/etc/linuxigd/
Jun 15 17:49:43 svr upnpd: UPnP Initialization Completed
Jun 15 17:49:43 svr upnpd: Setting webserver root directory -- /etc/linuxigd/
Jun 15 17:49:43 svr upnpd: Registering the root device
Jun 15 17:49:43 svr upnpd: RootDevice Registered
Jun 15 17:49:43 svr upnpd: Initializing State Table
Jun 15 17:49:43 svr upnpd: State Table Initialized
Jun 15 17:49:45 svr upnpd: Advertisements Sent

上面的192.168.0.1是网关计算机的eth1的IP地址。
在内部网络中的计算机上启动MSN Messenger,与Internet上的其他Messenger用户测试语音聊天、文件传输都可以正常使用了。
在/var/log/debug文件中看到如下信息:
Jun 15 17:53:47 svr upnpd: AddPortMap: RemoteHost: (null) Prot: 17 ExtPort: 2032 Int: 192.168.0.19.12216
Jun 15 17:53:47 svr upnpd: AddPortMap: RemoteHost: (null) Prot: 6 ExtPort: 31989 Int: 192.168.0.19.13767

还可以使用iptables -t nat -L命令查看NAT配置情况,upnpd可以在PREROUTING中动态添加和删除表项。
注意:firewall还需要根据上面MSN Messenger的端口要求进行配置,在INPUT中开放相应的端口,并且FORWARD也需要ACCEPT。

五、参考资料
"NAT HOWTO",http://www.netfilter.org/documentation/
"acket Filtering HOWTO",http://www.netfilter.org/documentation/
"Windows Messenger in Windows XP: Working with Firewalls and Network Address Translation Devices",
http://www.microsoft.com/windows ... t/natfw/default.asp
"UPnP NAT Traversal FAQ",http://www.microsoft.com/windows ... tworking/natfaq.asp
回复 支持 反对

使用道具 举报

发表于 2006-4-7 09:07:37 | 显示全部楼层
Post by jpzhu
作者:
dagger
无崖阁
xyg.ods.org

版本:
1.0        2003-06-22
        初始版本



这篇资料是不是老了点儿?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-4-7 09:10:45 | 显示全部楼层
网上找不到更新的了.所有中文用upnp的都是基于这一篇.
还有一位大侠说linux上面开一个socks代理就能解决,不过没找到实际操作方法.
upnp和libigd本身也是好久没有更新的东西了.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表