安装相关依赖及工具
| 1 | # apt-get install build-essential pkg-config libgnutls28-dev libreadline-dev libseccomp-dev libwrap0-dev libnl-nf-3-dev liblz4-dev gnutls-bin | 
下载安装
| 1 | # wget ftp://ftp.infradead.org/pub/ocserv/ocserv-0.10.8.tar.xz | 
安装
| 1 | # cd ocserv-0.10.8 | 
准备证书
| 1 | # cd ~ | 
创建证书模板
| 1 | # touch ca.tmpl server.tmpl | 
1) ca.tmpl模板内容如下:
| 1 | cn = "test.com" | 
2) serve.tmpl模板内容如下:
| 1 | cn = "hostname or IP" | 
生成CA和Server密钥
| 1 | # certtool --generate-privkey --outfile ca-key.pem | 
生成CA证书和Server证书
| 1 | # certtool --generate-self-signed --load-privkey ca-key.pem --template ca.tmpl --outfile ca-cert.pem | 
修改证书位置
| 1 | # cp ca-cert.pem /etc/ssl/certs/my-ca-cert.pem | 
编辑配置文件
| 1 | # mkdir /etc/ocserv | 
/etc/ocserv/ocserv.conf只需要修改以下条目:
| 1 | auth = "plain[/etc/ocserv/ocpasswd]" // 登陆方式,使用密码登录 | 
开启路由转发功能
开启系统转发
在/etc/sysctl.conf中添加如下代码:
| 1 | net.ipv4.ip_forward=1 | 
添加后使配置生效
| 1 | # sysctl -p | 
配置NAT转发
| 1 | # iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE | 
测试
添加测试账号
| 1 | # ocpasswd -c /etc/ocserv/ocpasswd test | 
连接测试
| 1 | # ocserv -f -d 1 // 启动调试模式 | 
客户端进行连接,地址是 IP:[端口]
如果可以连接则搭建完成
help
| 1 | # ocserv -c /etc/ocserv/ocserv.conf // 启动服务 |