Linux中国论坛's Archiver

神奇小猪 发表于 2008-7-22 22:55

命令行下配置CIPE

[align=center][size=22pt][b]命令行下配置CIPE VPN[/b][/size][/align]


[size=22pt][/size][size=10.5pt][font=宋体]对于没有这个工具(点击)的Linux发行版本(如RHEL 4.0 ,SUSE、红旗Linux)我们可以通过安装从CIPE软件的官方主页[url=http://sourceforge.net/projects/cipe-linux]http://sourceforge.net/projects/cipe-linux[/url]下载的源代码安装。下面笔者将介绍如何通过命令行配置CIPE VPN服务器。[/font][/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    [font=宋体]为了使管理员不必使用通过网络运行效果不佳的图形化工具来远程地配置 CIPE 服务器和客户,介绍通过配置文件建立CIPE VPN。首先理解前面介绍的图形界面系统产生两个配置文件:[/font][/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    /etc/cipe/options.cipcbx[/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    x [font=宋体]是从0开始的递增数字,这是为那些想要在 CIPE 服务器上不止有一个 CIPE 连接的客户提供。这个文件存放密匙,主要内容:[/font][/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    cttl 64 #[font=宋体]设置载体生存时间值(TTL);推荐的值是64#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    maxerr –1  #[font=宋体]服务器错误挂起时间#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    key 54240266869983357939377846806271299051 #128[font=宋体]位密匙#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    /etc/sysconfig/network-scripts/ifcfg-cipcb0[/size][size=10.5pt][/size]
[size=10.5pt]    CIPE[font=宋体]的网络接口,主要内容:[/font][/size][size=10.5pt][/size]
[size=10.5pt]    USERCTL=yes  #[font=宋体]是否允许所有用户修改配置#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    TYPE=CIPE    #[font=宋体]接口类型#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    DEVICE=cipcb0  #[font=宋体]给 CIPE 设备命名#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    ONBOOT=yes     #[font=宋体]系统启动时激活设备#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    IPADDR=10.0.0.1 #[font=宋体]本地虚拟地址#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    MYPORT=7777     #[font=宋体]通讯端口#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    PTPADDR=10.0.0.2 #[font=宋体]远程虚拟地址#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    PEER=0.0.0.0    #[font=宋体]本地地址,0.0.0.0 表示接受连续监听#[/font][/size][size=10.5pt][/size]
[size=10.5pt]   ME=192.168.0.9  #[font=宋体]对端的 CIPE UDP 地址#[/font][/size][size=10.5pt][/size]
[size=10.5pt]    TUNNELDEV=eth0  #[font=宋体]隧道穿越设备#[/font][/size][size=10.5pt][/size]
[size=10.5pt][b]   1. [font=宋体]软件安装[/font][/b][/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    [font=宋体]要设置 CIPE 服务器,可以通过网络来安装 cipe 软件包。下一步是把位于 /usr/share/doc/cipe-version/samples/ 的配置文件范例复制到 /etc/cipe/ 中(这里的 version 是安装在你的系统上的 CIPE 版本)。复制完毕后,你将需要编辑 /etc/cipe/options.cipcbx(x 是从0开始的递增数字,为那些想要在 CIPE 服务器上不止有一个 CIPE 连接的客户提供)文件来包括你的 LAN 子网地址和可公共选路的防火墙 IP 地址。以下是包括在RHEL 3.0的CIPE RPM 中的 options 文件范例。在这个例子中,它被重命名为 options.cipbcb0: [/font][/size][size=10.5pt][/size]
[size=10.5pt][/size]



[table][tr][td=1,1,568]
[size=10.5pt]  # the peer's IP address[/size][size=10.5pt][/size]
[size=10.5pt]   ptpaddr         6.5.4.3[/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    # our CIPE device's IP address[/size][size=10.5pt][/size]
[size=10.5pt]    ipaddr          6.7.8.9[/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    # my UDP address. Note: if you set port 0 here, the system will pick[/size][size=10.5pt][/size]
[size=10.5pt]    # one and tell it to you via the ip-up script. Same holds for IP 0.0.0.0.[/size][size=10.5pt][/size]
[size=10.5pt]    me              bigred.inka.de:6789[/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    # ...and the UDP address we connect to. Of course no wildcards here.[/size][size=10.5pt][/size]
[size=10.5pt]    peer            blackforest.inka.de:6543[/size][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]    # The static key. Keep this file secret![/size][size=10.5pt][/size]
[size=10.5pt]    # The key is 128 bits in hexadecimal notation.[/size][size=10.5pt][/size]
[size=10.5pt]    key             xxxxxxxxxxxxxxxxxxxxxxxxxxxxx[/size][size=10.5pt][/size]
[size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt]     [/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]ptpaddr [font=宋体]是远程 LAN 的 CIPE 地址。ipaddr 是工作站的 CIPE IP 地址。me 地址是客户的可公共选路的 IP 地址,它通过互联网发送 UDP 分组。peer 是 CIPE 服务器的可公共选路的 IP 地址。注意,客户工作站的 IP 地址是 0.0.0.0,因为它使用动态连接。CIPE 客户将会处理到 CIPE 服务器的连接。key 字段(用 x 代表;你的钥匙应该是密钥)是共享静态钥匙。这个钥匙在两个对端上必须是相同的,否则连接就不能成立。这是客户工作站将会使用的被编辑过的 /etc/cipe/options.cipcb0: [/font][/size]
[font=宋体][/font]
[font=宋体][/font]
[font=宋体][/font][size=10.5pt][/size]

[table][tr][td=1,1,568]

[size=10.5pt]ptpaddr        10.0.1.2[/size][size=10.5pt][/size]
[size=10.5pt]    ipaddr         10.0.1.1[/size][size=10.5pt][/size]
[size=10.5pt]    me             0.0.0.0[/size][size=10.5pt][/size]
[size=10.5pt]    peer           LAN.EXAMPLE.COM:6969[/size][size=10.5pt][/size]
[size=10.5pt]    key            123456ourlittlesecret7890shhhh[/size][size=10.5pt][/size]
[size=10.5pt]    [font=宋体]这是 CIPE 服务器的 /etc/cipe/options.cipcb0 文件: [/font][/size][size=10.5pt][/size]
[size=10.5pt]    ptpaddr        10.0.1.1[/size][size=10.5pt][/size]
[size=10.5pt]    ipaddr         10.0.1.2[/size][size=10.5pt][/size]
[size=10.5pt]    me             LAN.EXAMPLE.COM:6969[/size][size=10.5pt][/size]
[size=10.5pt]    peer           0.0.0.0[/size][size=10.5pt][/size]
[size=10.5pt]    key            123456ourlittlesecret7890shhhh[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][b]2. [font=宋体]配置客户的 CIPE[/font][/b][/size][size=10.5pt][/size]

[size=10.5pt][font=宋体]成功地配置了 CIPE [/font][/size][url=http://product.it168.com/files/0402search.shtml][size=10.5pt][font=宋体][color=#0000ff]服务器[/color][/font][/size][/url][size=10.5pt][font=宋体]并测试了它的功能后,你现在就可以在客户机器上使用这种连接了。CIPE 客户应该能够自动地连接和断开 CIPE 连接。因此,CIPE 包含内建的机制来为个别使用自定设置。例如,远程用户可以通过键入以下命令来连接到 LAN 上的 CIPE 设备:[/font][/size]
[font=宋体][/font]
[font=宋体][/font]
[font=宋体][/font][size=10.5pt][/size]

[table][tr][td=1,1,568][size=10.5pt]/sbin/ifup cipcb0[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt]  [/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][font=宋体]设备应该自动出现;防火墙规则和选路信息也应该和连接一起配置。远程职员应该能够使用以下命令来终止连接:[/font][/size]
[font=宋体][/font]
[font=宋体][/font]
[font=宋体][/font][size=10.5pt][/size]

[table][tr][td=1,1,568]
[size=10.5pt]/sbin/ifdown cipcb0[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]   [font=宋体]配置客户需要创建在设备被载入后需运行的脚本。服务配置本身可以通过用户创建的文件 /etc/sysconfig/network-scripts/ifcfg-cipcb0 来本地配置。这个文件中包含一些参数,如判定 CIPE 连接是否在引导时发生的参数;代表 CIPE 设备名称的参数等。以下是一个连接到 CIPE [/font][/size][url=http://server.it168.com/][size=10.5pt][font=宋体][color=#0000ff]服务器[/color][/font][/size][/url][size=10.5pt][font=宋体]的远程客户的 ifcfg-cipcb0 文件:[/font][/size]
[font=宋体][/font]
[font=宋体][/font]
[font=宋体][/font][size=10.5pt][/size]

[table][tr][td=1,1,568]
[size=10.5pt]DEVICE=cipcb0[/size][size=10.5pt][/size]
[size=10.5pt]   ONBOOT=yes[/size][size=10.5pt][/size]
[size=10.5pt]   BOOTPROTO=none[/size][size=10.5pt][/size]
[size=10.5pt]   USERCTL=no[/size][size=10.5pt][/size]
[size=10.5pt]   PEERROUTEDEV=[/size][size=10.5pt][/size]
[size=10.5pt]   DNS=192.168.1.254[/size][size=10.5pt][/size]
[/td][/tr][/table]
[size=10.5pt]   [/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt]CIPE [font=宋体]设备的名称是 cipcb0。CIPE 设备将会在引导时间被载入(通过 ONBOOT 字段配置),而且将不会使用一种引导协议(如 DHCP)来接收该设备的 IP 地址。PEERROUTEDEV 字段决定连接到客户的 CIPE 服务器设备名称。如果这个字段中没有指定任何设备,在设备被载入后就会为它决定一个。 如果你的内部[/font][/size][url=http://net.it168.com/][size=10.5pt][font=宋体][color=#0000ff]网络[/color][/font][/size][/url][size=10.5pt][font=宋体]是在防火墙背后,你需要设置规则来允许客户机器上的 CIPE 接口发送和接收 UDP 分组。我们这个配置例子中使用了 iptables 规则。客户机器上的防火墙应该被配置接受 CIPE UDP 封装分组。规则的差距可能会很大,但是对 UDP 分组的基本接受对于 CIPE 连接来说却是必需的。以下的 iptables 规则允许连接到 LAN 上的远程客户机器进行 UDP CIPE 传输;最后一条规则添加了 IP 伪装来允许远程客户与 LAN 和互联网[/font][/size][url=http://tele.it168.com/][size=10.5pt][font=宋体][color=#0000ff]通信[/color][/font][/size][/url][size=10.5pt][font=宋体]。 [/font][/size][size=10.5pt][/size]




[size=10.5pt][/size]

[table][tr][td=1,1,568][size=10.5pt]   /sbin/modprobe iptables[/size][size=10.5pt][/size]
[size=10.5pt]   /sbin/service iptables stop[/size][size=10.5pt][/size]
[size=10.5pt]   /sbin/iptables -P INPUT DROP[/size][size=10.5pt][/size]
[size=10.5pt]   /sbin/iptables -F INPUT[/size][size=10.5pt][/size]
[size=10.5pt]   /sbin/iptables -A INPUT -j ACCEPT -p udp -s 10.0.1.1[/size][size=10.5pt][/size]
[size=10.5pt]   /sbin/iptables -A INPUT -j ACCEPT -i cipcb0[/size][size=10.5pt][/size]
[size=10.5pt]   /sbin/iptables -A INPUT -j ACCEPT -i lo[/size][size=10.5pt][/size]
[size=10.5pt]   /sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt]   [/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][font=宋体]客户端需要添加以下内容:[/font][/size][size=10.5pt][/size]
[size=10.5pt]   route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.1.2[/size][size=10.5pt][/size]
[size=10.5pt]   [font=宋体]表-2详细描述了一些运行 ciped 守护进程时的命令行参数。[/font][/size][size=10.5pt][/size]





[size=10.5pt][/size]

[table][tr][td=1,1,143][align=center]
[size=12pt][b]参数[/b][/size][size=10.5pt][/size][/align]
[/td][td=1,1,424][align=center][size=12pt][b]描述[/b][/size][size=10.5pt][/size][/align]
[/td][/tr][tr][td=1,1,143][size=12pt]arg[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]把参数传递给 /etc/cipe/ip-up [/size][size=12pt]初始脚本[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]cttl[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]设置载体生存时间值(TTL[/size][size=12pt]);推荐的值是64[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]debug[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]启用调试的布尔值[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]device[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]给 CIPE [/size][size=12pt]设备命名[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]ipaddr[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]CIPE 机器的可公开选路的 IP [/size][size=12pt]地址[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]ipdown[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]选择另一个 ip-down [/size][size=12pt]脚本,而不是默认的 /etc/cipe/ip-down[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]ipup[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]选择另一个 ip-up [/size][size=12pt]脚本,而不是默认的 /etc/cipe/ip-up[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]key[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]为 CIPE [/size][size=12pt]连接指定一个共享静态密钥[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]maxerr[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]在 CIPE [/size][size=12pt]守护进程退出前允许的错误数量[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]me[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]CIPE 机器的 UDP [/size][size=12pt]地址[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]mtu[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]设置设备的最大传输单位[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]nokey[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]不使用加密[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]peer[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]对端的 CIPE UDP [/size][size=12pt]地址[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]ping[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]设置 CIPE [/size][size=12pt]特有的(非 ICMP)保持活跃 ping 间隔[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]socks[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]用于代理连接的 SOCKS [/size][size=12pt]服务器的 IP 地址和端口号码[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]tokey[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]设置[/size][size=12pt][i]动态[/i][/size][size=12pt]钥匙的活跃时间;默认为10[/size][size=12pt]分钟(600秒)[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]tokxc[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]共享钥匙互换的超时值;默认为10[/size][size=12pt]秒钟[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]tokxts[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]共享钥匙互换时间戳的超时值;默认为0[/size][size=12pt](无时间戳)[/size][size=10.5pt][/size]
[/td][/tr][tr][td=1,1,143][size=12pt]toping[/size][size=10.5pt][/size]
[/td][td=1,1,424][size=12pt]保存活跃 ping [/size][size=12pt]的超时值;默认为0[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][/size]
[size=10.5pt][b]3. CIPE [font=宋体]的钥匙管理[/font][/b][/size][size=10.5pt][/size]

[size=10.5pt][font=宋体]如前面所提到,CIPE 包括一个静态链接钥匙(link key)和加密交通的[/font][/size][url=http://safe.it168.com/][size=10.5pt][font=宋体][color=#0000ff]安全[/color][/font][/size][/url][size=10.5pt][font=宋体]组合来在载体[/font][/size][url=http://net.it168.com/][size=10.5pt][font=宋体][color=#0000ff]网络[/color][/font][/size][/url][size=10.5pt][font=宋体]如互联网中创建一个安全隧道。静态链接钥匙为两个启用了 CIPE 的网络安全传递信息提供了一个公共参考点。因此,这两个启用了 CIPE 的网络[/font][/size][url=http://product.it168.com/list/b/0474_1.shtml][size=10.5pt][font=宋体][color=#0000ff]网关[/color][/font][/size][/url][size=10.5pt][font=宋体]分享完全相同的钥匙这一点是极端重要的,否则 CIPE [/font][/size][url=http://tele.it168.com/][size=10.5pt][font=宋体][color=#0000ff]通信[/color][/font][/size][/url][size=10.5pt][font=宋体]就不能够进行。[/font][/size][size=10.5pt][/size]
[size=10.5pt]   [font=宋体]生成 CIPE 钥匙需要你懂得哪类钥匙是兼容的。随机的字母数字生成器是行不通的。静态钥匙必须是128位、32字符的字符串。这些字符串可以通过运行以下命令来被创建。该命令使用 od 来创建使用 /dev/random 随机数字设备的十六进制密钥: [/font][/size]
[font=宋体][/font]
[font=宋体][/font]
[font=宋体][/font][size=10.5pt][/size]

[table][tr][td=1,1,568]
[size=10.5pt]od -N 16 /dev/random -t x4 | awk '{print $2 $3 $4 $5}'[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt]   [/size]
[size=10.5pt][/size]
[size=10.5pt][font=宋体]把输出放在 /etc/cipe/options.cipcb0 文件中以用于所有 CIPE [/font][/size][url=http://product.it168.com/files/0402search.shtml][size=10.5pt][font=宋体][color=#0000ff]服务器[/color][/font][/size][/url][size=10.5pt][font=宋体]和客户。 [/font][/size]
[font=宋体][/font]
[font=宋体][/font][size=10.5pt][/size]


[size=10.5pt][b]4. [font=宋体]安全提示:[/font][/b][/size][size=10.5pt][/size]
[size=10.5pt]  [font=宋体]如果你使用的是较老的红帽企业 Linux,并且/或者有一个较老的 CIPE,你应该升级到最新的版本。[/font][/size][size=10.5pt][/size]
[size=10.5pt]   [font=宋体]总结:[/font][/size][size=10.5pt][/size]
[size=10.5pt]   CIPE[font=宋体]可以快速实现Linux[/font][/size][url=http://server.it168.com/][size=10.5pt][font=宋体][color=#0000ff]服务器[/color][/font][/size][/url][size=10.5pt][font=宋体]和主机之间的VPN连接。现在也有用于 Windows 的[/font][/size][url=http://product.it168.com/list/b/0501_1.shtml][size=10.5pt][font=宋体][color=#0000ff]操作系统[/color][/font][/size][/url][size=10.5pt][font=宋体]的CIPE的项目在开发中,详情查看:[/font][/size][url=http://cipe-win32.sourceforge.net/][size=10.5pt][color=#0000ff]http://cipe-win32.sourceforge.net/[/color][/size][/url][size=10.5pt] [font=宋体]。[/font][/size][size=10.5pt][/size]

[[i] 本帖最后由 神奇小猪 于 2008-7-22 22:57 编辑 [/i]]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.