利用openbsd+openvpn快速建立企業vpn
openvpn可工作於兩種模式:
一種是IP遂道路由模式,主要應用於點對點
一種是基於乙太網的遂道橋模式, 應用於點對多點,有多個分支機構
本文介紹的配置實例是第一種
區域網1:
OFFICE主機裝openbsd3.4 兩塊網卡
rl1接公網 61.131.58.x ,
rl0接 內網192.168.1.222
vpn 10.1.0.1
A client主機 192.168.1.22
區域網2:
HOME主機裝redhat9.0兩塊網卡
rl1 接公網 218.85.158.244
rl0 接內網 192.168.0.222
vpn 10.1.0.2
B client主機 192.168.0.45
環境:openbsd3.4+lzo+openssl+openvpn
openssl用來進行加密,lzo用來進行數據壓縮
下載地址 http://prdownloads.sourceforge.net/openvpn/openvpn-2.0_beta7.tar.gz
http://www.oberhumer.com/opensource/lzo/download/lzo-1.08.tar.gz
openbsd的安裝就不說了
openssl在openbsd下是默認安裝的
我將openvpn-2.0.beta7.tar.gz和lzo-1.08.tar.gz下載到/home
#cd /home
#tar zxvf lzo-1.08.tar.gz
#cd lzo-1.08.
#./comfigure
#make
#make install
#tar zxvf openvpn-2.0_beta7.tar.gz
#cd openvpn-2.0_beta7
#./configure --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib
#make
#make install
#mkdir /etc/openvpn
#cd /etc/openvpn
#openvpn --genkey --secret static.key
將static.key從office主機複製到home主機的/etc/openvpn目錄中
office#scp static.key root@218.85.158.244:/etc/openvpn
參考/home/openvpn-2.0_beta7/sample-config-files下的文件
建立以下幾個配置文件及腳本文件
office.up和openvpn-startup.sh腳本
static-office.conf配置文件
我的office主機的配置例子如下
office.up如下
#!/bin/sh
route add -net 192.168.0.0/24 10.1.0.2
openvpn-startup.sh如下
#!/bin/sh
/usr/local/sbin/openvpn --config /etc/openvpn/static-office.conf
static-office.conf如下
dev tun0
remote 218.85.158.244
ifconfig 10.1.0.1 10.1.0.2
up ./office.up
secret /etc/openvpn/static.key
port 5000
comp-lzo
ping 15
ping 15
ping-restart 45
ping-timer-rem
persist-tun
persist-key
verb 3
我的home主機的配置例子如下
home.up如下
#!/bin/sh
route add –net 192.168.1.0/24 10.1.0.1
openvpn-startup.sh如下
#!/bin/sh
/usr/local/sbin/openvpn --config /etc/openvpn/static-home.conf
static-home.conf如下
dev tun0
remote 61.131.58.x
ifconfig 10.1.0.2 10.1.0.1
up ./home.up
secret /etc/openvpn/static.key
port 5000
comp-lzo
ping 15
ping 15
ping-restart 45
ping-timer-rem
persist-tun
persist-key
verb 3
在office主機及home主機兩端起用pf防火牆,編輯/etc/sysctl.conf
net.inet.ip.forwarding=1
net.inet6.ip6.forwarding=1並去掉前面的#號
編輯/etc/rc.conf
pf=YES
我的office主機的pf.conf如下:
ext_if="rl1" # replace with actual external interface name i.e., dc0
int_if="rl0" # replace with actual internal interface name i.e., dc1
internal_net="192.168.1.0/24"
priv_nets="{
127.0.0.0/8,
192.168.0.0/16,
172.16.0.0/12,
10.0.0.0/8
}"
set optimization aggressive
scrub in all
nat on $ext_if from $internal_net to any -> 61.131.58.x/32
block all
pass quick on lo0 all
pass quick on tun0 all
pass in on $int_if from any to any keep state
pass out on $int_if from any to any keep state
block drop in quick on $ext_if from $priv_nets to any
block drop out quick on $ext_if from any to $priv_nets
pass out on $ext_if proto tcp all modulate state flags S/SA
pass out on $ext_if proto { udp,icmp } all keep state
我的home主機的pf.conf如下:
ext_if="rl1" # replace with actual external interface name i.e., dc0
int_if="rl0" # replace with actual internal interface name i.e., dc1
internal_net="192.168.0.0/24"
priv_nets="{
127.0.0.0/8,
192.168.0.0/16,
172.16.0.0/12,
10.0.0.0/8
}"
set optimization aggressive
scrub in all
nat on $ext_if from $internal_net to any -> 218.85.158.244/32
block all
pass quick on lo0 all
pass quick on tun0 all
pass in on $int_if from any to any keep state
pass out on $int_if from any to any keep state
block drop in quick on $ext_if from $priv_nets to any
block drop out quick on $ext_if from any to $priv_nets
pass out on $ext_if proto tcp all modulate state flags S/SA
pass out on $ext_if proto { udp,icmp } all keep state
重起office和home主機
#cd /etc/openvpn
#./openvpn-startup.sh
在區域網1 A client端 ping 區域網2 b client端
ping 192.168.0.45
(責任編輯:A6)
[火星人 ] 利用Openbsd和Openvpn快速建立企業的VPN已經有886次圍觀