服务器

1

root@ubuntu:~# ifconfig

as0t0 Link encap:未指定 硬件地址 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00

inet 地址:5.5.0.1 点对点:5.5.0.1 掩码:255.255.248.0

UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 跃点数:1

接收数据包:0 错误:0 丢弃:0 过载:0 帧数:0

发送数据包:0 错误:0 丢弃:0 过载:0 载波:0

碰撞:0 发送队列长度:200

接收字节:0 (0.0 B) 发送字节:0 (0.0 B)

as0t1 Link encap:未指定 硬件地址 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00

inet 地址:5.5.8.1 点对点:5.5.8.1 掩码:255.255.248.0

UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 跃点数:1

接收数据包:7072 错误:0 丢弃:0 过载:0 帧数:0

发送数据包:6776 错误:0 丢弃:0 过载:0 载波:0

碰撞:0 发送队列长度:200

接收字节:703269 (703.2 KB) 发送字节:2863127 (2.8 MB)

eth0 Link encap:以太网 硬件地址 00:1e:ec:c3:07:38

inet 地址:219.245.89.89 广播:219.245.89.255 掩码:255.255.255.0

inet6 地址: fe80::21e:ecff:fec3:738/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1

接收数据包:95993 错误:0 丢弃:0 过载:0 帧数:0

发送数据包:90551 错误:0 丢弃:0 过载:0 载波:0

碰撞:0 发送队列长度:1000

接收字节:36113891 (36.1 MB) 发送字节:51139258 (51.1 MB)

中断:18 基本地址:0xd800

eth1 Link encap:以太网 硬件地址 00:e0:4c:f0:26:e1

inet 地址:192.168.0.1 广播:192.168.0.255 掩码:255.255.255.0

inet6 地址: fe80::2e0:4cff:fef0:26e1/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1

接收数据包:19317 错误:0 丢弃:0 过载:0 帧数:0

发送数据包:20911 错误:0 丢弃:0 过载:0 载波:0

碰撞:0 发送队列长度:1000

接收字节:2919480 (2.9 MB) 发送字节:20111031 (20.1 MB)

中断:19 基本地址:0xd400

lo Link encap:本地环回

inet 地址:127.0.0.1 掩码:255.0.0.0

inet6 地址: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 跃点数:1

接收数据包:11028 错误:0 丢弃:0 过载:0 帧数:0

发送数据包:11028 错误:0 丢弃:0 过载:0 载波:0

碰撞:0 发送队列长度:0

接收字节:41685343 (41.6 MB) 发送字节:41685343 (41.6 MB)

分析:

as0t0接收和发送字节数为0来看,as0t0应该没用到,这块虚拟网卡有什么用?或者说服务器为什么有两块虚拟网卡?5.5.0.15.5.8.1在子网掩码255.255.248.0下是不是一个网段!5.5.0.1/21表示5.5.0.1——5.5.7.2555.5.8.1表示5.5.8.1——5.5.15.255(计算方法,5.5.8.1前面21位不变,余下位全为1

这里的点对点如何理解?

 

2

root@ubuntu:~# route -n

内核 IP 路由表

目标 网关 子网掩码 标志 跃点 引用 使用 接口

219.245.89.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

5.5.0.0 0.0.0.0 255.255.248.0 U 0 0 0 as0t0

5.5.8.0 0.0.0.0 255.255.248.0 U 0 0 0 as0t1

169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth1

0.0.0.0 219.245.89.254 0.0.0.0 UG 0 0 0 eth0

分析:

目标地址为5.5.8.0/255.255.248.0的网段是客户端虚拟网段,

5.5.0.0/255.255.248.0网段呢?

去掉该条路由呢?

route del -net 5.5.0.0 netmask 255.255.248.0(终端操作,未进行网络重启操作);

删除这条路由对终端ping 百度无影响;

但删除另一条

route del -net 5.5.8.0 netmask 255.255.248.0

客户端ping 百度无响应,但仍可在服务器端看到截获的包!

添加route add -net 5.5.8.0 netmask 255.255.248.0 dev as0t1

客户端再ping百度有响应!!

 

综上所述:目标地址为5.5.8.0的那条路由跟转发有关,去掉该条,

服务器仍可看到截获的包(截获应和客户端有关,即看客户端封装后发给谁),

但是没有转发出去!

 

3。转发还得看iptables

root@ubuntu:~# iptables-save

# Generated by iptables-save v1.4.4 on Wed Aug 22 16:11:05 2012

*mangle

:PREROUTING ACCEPT [37781:3441345]

:INPUT ACCEPT [83316:56485864]

:FORWARD ACCEPT [29705:11635358]

:OUTPUT ACCEPT [72943:88733163]

:POSTROUTING ACCEPT [102557:100363435]

:AS0_MANGLE_PRE_REL_EST - [0:0]

:AS0_MANGLE_TUN - [0:0]

-A PREROUTING -m state --state RELATED,ESTABLISHED -j AS0_MANGLE_PRE_REL_EST

-A PREROUTING -i as0t+ -j AS0_MANGLE_TUN

-A AS0_MANGLE_PRE_REL_EST -j ACCEPT

-A AS0_MANGLE_TUN -j MARK --set-xmark 0x2000000/0xffffffff

-A AS0_MANGLE_TUN -j ACCEPT

COMMIT

# Completed on Wed Aug 22 16:11:05 2012

# Generated by iptables-save v1.4.4 on Wed Aug 22 16:11:05 2012

*nat

:PREROUTING ACCEPT [16598:1611064]

:OUTPUT ACCEPT [2931:189542]

:POSTROUTING ACCEPT [2931:189542]

:AS0_NAT - [0:0]

:AS0_NAT_POST_REL_EST - [0:0]

:AS0_NAT_PRE - [0:0]

:AS0_NAT_PRE_REL_EST - [0:0]

:AS0_NAT_TEST - [0:0]

-A PREROUTING -m state --state RELATED,ESTABLISHED -j AS0_NAT_PRE_REL_EST

-A POSTROUTING -m state --state RELATED,ESTABLISHED -j AS0_NAT_POST_REL_EST

-A POSTROUTING -m mark --mark 0x2000000/0x2000000 -j AS0_NAT_PRE

-A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE

-A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE

-A AS0_NAT -o eth0 -j SNAT --to-source 219.245.89.89

-A AS0_NAT -o eth1 -j SNAT --to-source 192.168.0.1

-A AS0_NAT -j ACCEPT

-A AS0_NAT_POST_REL_EST -j ACCEPT

-A AS0_NAT_PRE -d 5.5.0.0/20 -j AS0_NAT_TEST

-A AS0_NAT_PRE -d 192.168.0.0/16 -j AS0_NAT_TEST

-A AS0_NAT_PRE -d 172.16.0.0/12 -j AS0_NAT_TEST

-A AS0_NAT_PRE -d 10.0.0.0/8 -j AS0_NAT_TEST

-A AS0_NAT_PRE -j AS0_NAT

-A AS0_NAT_PRE_REL_EST -j ACCEPT

-A AS0_NAT_TEST -o as0t+ -j ACCEPT

-A AS0_NAT_TEST -d 5.5.0.0/20 -j ACCEPT

-A AS0_NAT_TEST -j AS0_NAT

COMMIT

# Completed on Wed Aug 22 16:11:05 2012

# Generated by iptables-save v1.4.4 on Wed Aug 22 16:11:05 2012

*filter

:INPUT ACCEPT [28141:2771549]

:FORWARD DROP [124:7519]

:OUTPUT ACCEPT [72665:88709799]

:AS0_ACCEPT - [0:0]

:AS0_IN - [0:0]

:AS0_IN_POST - [0:0]

:AS0_IN_PRE - [0:0]

:AS0_OUT - [0:0]

:AS0_OUT_LOCAL - [0:0]

:AS0_OUT_S2C - [0:0]

:AS0_WEBACCEPT - [0:0]

-A INPUT -m state --state RELATED,ESTABLISHED -j AS0_ACCEPT

-A INPUT -i lo -j AS0_ACCEPT

-A INPUT -m mark --mark 0x2000000/0x2000000 -j AS0_IN_PRE

-A INPUT -d 219.245.89.89/32 -p udp -m state --state NEW -m udp --dport 1194 -j AS0_ACCEPT

-A INPUT -d 219.245.89.89/32 -p tcp -m state --state NEW -m tcp --dport 443 -j AS0_ACCEPT

-A INPUT -m state --state RELATED,ESTABLISHED -j AS0_WEBACCEPT

-A INPUT -d 219.245.89.89/32 -p tcp -m state --state NEW -m tcp --dport 943 -j AS0_WEBACCEPT

-A FORWARD -m state --state RELATED,ESTABLISHED -j AS0_ACCEPT

-A FORWARD -m mark --mark 0x2000000/0x2000000 -j AS0_IN_PRE

-A FORWARD -o as0t+ -j AS0_OUT_S2C

-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

-A FORWARD -m mac --mac-source 00:16:D3:BA:FC:E6 -j ACCEPT

-A FORWARD -m mac --mac-source 20:6A:8A:43:BA:E3 -j ACCEPT

。。。省略MAC白名单

-A OUTPUT -o as0t+ -j AS0_OUT_LOCAL

-A AS0_ACCEPT -j ACCEPT

-A AS0_IN -d 5.5.0.1/32 -j ACCEPT

-A AS0_IN -d 192.168.0.0/24 -j ACCEPT

-A AS0_IN -j AS0_IN_POST

-A AS0_IN_POST -o as0t+ -j AS0_OUT

-A AS0_IN_POST -j DROP

-A AS0_IN_PRE -d 5.5.0.0/20 -j AS0_IN

-A AS0_IN_PRE -d 192.168.0.0/16 -j AS0_IN

-A AS0_IN_PRE -d 172.16.0.0/12 -j AS0_IN

-A AS0_IN_PRE -d 10.0.0.0/8 -j AS0_IN

-A AS0_IN_PRE -j ACCEPT

-A AS0_OUT -j DROP

-A AS0_OUT_LOCAL -p icmp -m icmp --icmp-type 5 -j DROP

-A AS0_OUT_LOCAL -j ACCEPT

-A AS0_OUT_S2C -j AS0_OUT

-A AS0_WEBACCEPT -j ACCEPT

COMMIT

# Completed on Wed Aug 22 16:11:05 2012

 

 

iptables的分析:

1/清空iptables规则后vpn不能正常使用。

(补充,将规则导入文件:iptables-save > myiptables.txt 将文件中内容导入iptablesiptables-save < myiptables.txt

2/关键分析nat-A AS0_NAT -o eth0 -j SNAT --to-source 219.245.89.89

-A AS0_NAT -o eth1 -j SNAT --to-source 192.168.0.1

 

 

 

 

 

 

 

 

 

附图:服务器端抓包情况