在FC1里面的openvpn配置
时间:2005-12-31 来源:ruiqingzheng
参考 http://bbs.chinaunix.net/viewthread.php?tid=503434
安装部分
shell > yum install gcc
shell > yum install gcc-c++
安装lzo实时压缩工具
1. wget ttp://www.oberhumer.com/opensource/lzo/download/lzo-2.00.tar.gz
2. setup : configure && make && make install
安装openssl
shell > yum install openssl
shell > yum install openssl-devel
安装openvpn
wget http://mesh.dl.sourceforge.net/sourceforge/openvpn/openvpn-2.0_rc16.tar.gz
configure --with-lzo-headers=/usr/local/include/lzo --with-lzo-lib=/usr/local/lib
# 需要的话手动指定openssl的头文件和库文件 ,
FC1里面自动可以找到 --with-ssl-headers=DIR
Crypto/SSL Include files location --with-ssl-lib=DIR Crypto/SSL Library location
make && make install
阅读OPENVPN里面的INSTALL文件创建一个tun设备
并加载tun模块
TUN/TAP Driver Configuration:
* Linux 2.4 or higher (with integrated TUN/TAP driver):
(1) make device node: mknod /dev/net/tun c 10 200
(2a) add to /etc/modules.conf: alias char-major-10-200 tun
(2b) load driver: modprobe tun
(3) enable routing: echo 1 > /proc/sys/net/ipv4/ip_forward
Note that either of steps (2a) or (2b) is sufficient. While (2a) only needs to be done once per install, (2b) needs to be done once per reboot. If you install from RPM (see above) and use the openvpn.init script, these steps are taken care of for you.
证书和KEY的生成部分
#在编译openvpn目录下操作
shell > mkdir /etc/openvpn
shell > cp -rp easy-rsa /etc/openvpn
#切换到/etc/openvpn目录下
shell > cd /etc/openvpn/easy-rsa
修改vars文件 vars文件中定义生成证书和KEY的时候需要读取的变量
主要更改最后面的几行
export KEY_COUNTRY=CN # 定义你所在的国家,2个字符
export KEY_PROVINCE=HUBEI # 你所在的省份
export KEY_CITY=WUHAN # 你所在的省份
export KEY_ORG="YIDAORG" # 你所在的组织
export KEY_OU="NET" # 你的单位
export KEY_EMAIL="[email protected]" # 你的邮件地址
保存vars文件
source执行 使变量生效 , 然后开始生成证书和KEY
shell > . ./vars
shell > ./clean-all #初始化keys目录,创建所需要的文件和目录
shell > ./build-ca #什成Root CA证书,用于签发Server和Client证书(ca.crt ca.key)
shell > ./build-dh #TLS server 需要使用的一个文件 (dh1024.pem)
shell > ./build-key-server server
#创建并签发VPN Server使用的CA (server.crt server.key server.csr 01.pem)
下面为client颁发CA证书 如果以后要为其他Client颁发证书,直接使用build-key命令签发新证书。
shell > ./build-key client (client.crt client.key client.csr 02.pem)
为防止恶意攻击(如DOS、UDP port flooding),我们生成一个"HMAC firewall"
shell > openvpn --genkey --secret keys/ta.key
生成证书吊销链文件,防止日后有人丢失证书,被非法用户接入VPN
shell > ./make-crl vpncrl.pem
server端配置文件部分
vi /etc/openvpn/server.conf
port 1194
proto udp
dev tap
ca ca.crt
cert server.crt
key server.key
crl-verify vpncrl.pem
dh dh1024.pem
server 192.168.1.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-to-client
keepalive 10 120
tls-auth ta.key 0
comp-lzo
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
log /var/log/openvpn.log
verb 3
保存退出
把easy-rsa/keys下面的key复制到/etc/openvpn
shell > cd /etc/openvpn
shell > cp /etc/openvpn/easy-rsa/keys/{ca.crt,server.crt,server.key,dh1024.pem,ta.key,vpncrl.pem} .
创建OpenVPN启动脚本,可以在源代码目录中找到,在sample-scripts目录下的openvpn.init文件,将其复制到/etc/init.d/目录中,改名为openvpn
shell > cp sample-scripts/openvpn.init /etc/rc.d/init.d/openvpn
shell > chkconfig -add openvpn
shell > chkconfig openvpn on
shell > /etc/init.d/openvpn start
client 端配置(WIN2000下测试)
安装openvpn-gui 注意要tap-win32 virtual ether adapter 装上去
client端首先需要把 server端生成的 根证书(ca.crt)
client证书(client.crt)
client证书KEY(client.key)
防止攻击的key(ta.key)
上面文件拷贝到客户机
配置文件client.ovpn
CODE:[Copy to clipboard]
client dev tap
proto udp
remote 192.168.0.249 1194
resolv-retry infinite
nobind persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
ns-cert-type server
tls-auth ta.key 1
comp-lzo
verb 4
需要为客户端指定网关为192.168.1.1
route add 0.0.0.0 mask 0.0.0.0 192.168.1.1
server端再进行 snat 才可以正常访问
iptables -t nat -s 192.168.1.1 -j SNAT --to 192.168.100.254
在客户端配置文件中加上一条到拨号的内网的路由
route 192.168.100.0 255.255.255.0
WIN下拨号成功后 可以看到 有这一句后 路由表中增加了一条到192.168.100.0的路由
route print destination mask gateway interface
192.168.100.0 255.255.255.0 192.168.1.1 192.168.1.2