文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>策略路由条件下,openvpn访问内网的问题

策略路由条件下,openvpn访问内网的问题

时间:2010-06-10  来源:lwtcn

由于原来的网络有2个代理出口,一个是squid 192.168.6.110,一个是微软的代理服务器192.168.6.253,同时内网又分了192.168.3.0/24,4,5,6,7,8,9,10等段,所以对特定的网段进行了策略路由:
基本思路如下: 4、5、7、8、9、10段走squid 3、6段走微软的代理 同时除了6段外,其他的段均是从192.168.0.1路由器路由过来的。

具体如下: cat /etc/iproute2/rt_tables
# # reserved values # 255     local 254     main 253     default 0       unspec 200     net10   (从3、6段来的访问0/0的,扔给192.168.6.253) 100     net9    (192.168.6.110的回包到3、4、5、7、8、9、10段,通过192.168.6.1) 80      net8    (3、6段访问192.168.6.110能通)

cat /opt/route/route
#!/bin/sh ip route add to 192.168.6.110 via 192.168.6.110 dev eth1 table net8 ip rule add from 192.168.6.0/24 pref 8000 table net8  ip rule add from 192.168.3.0/24 pref 8001 table net8
ip route add to 192.168.0.0/16 via 192.168.6.1 dev eth1 table net9 ip rule add to 192.168.3.0/24 pref 9000 table net9 ip rule add to 192.168.4.0/24 pref 9001 table net9 ip rule add to 192.168.5.0/24 pref 9002 table net9 ip rule add to 192.168.7.0/24 pref 9003 table net9 ip rule add to 192.168.8.0/24 pref 9004 table net9 ip rule add to 192.168.9.0/24 pref 9005 table net9 ip rule add to 192.168.10.0/24 pref 9006 table net9
ip route add to 0.0.0.0/0 via 192.168.6.253 dev eth1 table net10 ip rule add from 192.168.6.0/24 pref 10000 table net10  ip rule add from 192.168.3.0/24 pref 10001 table net10


今天做了此服务器的openvpn: openvpn的服务器虚拟网络:  inet addr:10.12.0.1  P-t-P:10.12.0.2  Mask:255.255.255.255 远程我的登入的用户分配的是:  10.12.0.6/255.255.255.252   网关 10.12.0.5

由于原有的iptables的策略中有: $IPT -t nat -A POSTROUTING -s 10.12.0.0/16 -o $LOCAL_IFACE -j SNAT --to-source $LOCAL_IP

发现原有的vpn访问内网功能不行了,如:远程vpn客户端ping 192.168.6.110 不通 研究了下,自己认为原因如下: 由于tun0访问内网先源地址转换为$LOCAL_IP(192.168.6.110),会先符合上面的net8的 策略路由,这个去的包没问题。但是回包的话。对于eth1的设备,由于POSTROUTING级别比较低,会先处理net10的策略,这样回包就会被扔走,给192.168.6.253。

解决办法如下:
更改:iptables里面的策略
#$IPT -t nat -A POSTROUTING -s 10.12.0.0/16 -o $LOCAL_IFACE -j SNAT --to-source $LOCAL_IP
屏蔽源地址nat的iptables的策略,通过路由方式来解决内网访问问题。

新建2个路由表,net7、net6
cat /etc/iproute2/rt_tables 
# # reserved values # 255     local 254     main 253     default 0       unspec 200     net10 100     net9 80      net8 70      net7 60      net6 # # local # #1      inr.ruhep

增加策略路由如下: cat /opt/route/route
#!/bin/sh
ip route add to 192.168.6.0/24 via 192.168.6.110 dev eth1 table net6 ip rule add from 10.12.0.0/16 pref 6000 table net6
ip route add to 10.12.0.0/16 via 10.12.0.1 dev tun0 table net7 ip rule add from 192.168.0.0/16 pref 7000 table net7
ip route add to 192.168.6.110 via 192.168.6.110 dev eth1 table net8 ip rule add from 192.168.6.0/24 pref 8000 table net8  ip rule add from 192.168.3.0/24 pref 8001 table net8
ip route add to 192.168.0.0/16 via 192.168.6.1 dev eth1 table net9 ip rule add to 192.168.3.0/24 pref 9000 table net9 ip rule add to 192.168.4.0/24 pref 9001 table net9 ip rule add to 192.168.5.0/24 pref 9002 table net9 ip rule add to 192.168.7.0/24 pref 9003 table net9 ip rule add to 192.168.8.0/24 pref 9004 table net9 ip rule add to 192.168.9.0/24 pref 9005 table net9 ip rule add to 192.168.10.0/24 pref 9006 table net9
ip route add to 0.0.0.0/0 via 192.168.6.253 dev eth1 table net10 ip rule add from 192.168.6.0/24 pref 10000 table net10  ip rule add from 192.168.3.0/24 pref 10001 table net10

测试结果: 远程vpn :ping 192.168.6.110  符合net6通过          ping 192.168.3.47   符合net9通过    服务器: ping 10.12.0.6   符合net7通过
这里要注意的是:net7 中的dev是tun0  同时via 10.12.0.1
还要注意的是 要关掉远程vpn客户机的防火墙。

这里提供了一个使用路由方式来解决,远程vpn访问内网的方法。
对于源地址转换的nat方式为什么不能访问的分析,也不知道是对不对(希望有高手解答)。
阿涛原创。转载注明。
相关阅读 更多 +
排行榜 更多 +
哥布林弹球b服手游下载

哥布林弹球b服手游下载

休闲益智 下载
小马样式盒游戏下载

小马样式盒游戏下载

休闲益智 下载
异变小镇中文版下载安装

异变小镇中文版下载安装

冒险解谜 下载