CentOS6.5安裝ocserv

來源:互聯網
上載者:User

CentOS6.5安裝ocserv

1、編譯nettle
安裝gmp
yum install gmp-devel gmp
wget http://ftp.gnu.org/gnu/nettle/nettle-2.7.1.tar.gz
tar zxf nettle-2.7.1.tar.gz && cd nettle-2.7.1
./configure –prefix=/usr && make
make install &&
chmod -v 755 /usr/lib/libhogweed.so.2.5 /usr/lib/libnettle.so.4.7 &&
install -v -m755 -d /usr/share/doc/nettle-2.7.1 &&
install -v -m644 nettle.html /usr/share/doc/nettle-2.7.1

2、編譯unbound
安裝expat-devel
yum install expat-devel
wget http://unbound.nlnetlabs.nl/downloads/unbound-1.4.22.tar.gz
tar zxf unbound-1.4.22.tar.gz && cd unbound-1.4.22
./configure && make && make install
mkdir -p /etc/unbound && unbound-anchor -a “/etc/unbound/root.key”

3、編譯gnutls
wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.2/gnutls-3.2.12.1.tar.xz
xz -c -d gnutls-3.2.12.1.tar.xz | tar x
cd gnutls-3.2.12
./configure –prefix=/usr && make && make install

4、編譯ocserv
wget ftp://ftp.infradead.org/pub/ocserv/ocserv-0.3.2.tar.xz
xz -c -d ocserv-0.3.2.tar.xz | tar x
cd ocserv-0.3.2
./configure && make && make install
如果nettle和gnutls安裝在/usr/local目錄,需要運行以下命令設定系統變數,再運行./configure。同時要把這些命令加進系統啟動裡。
32bit
export LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/lib64/ NETTLE_CFLAGS=”-I/usr/local/include/” NETTLE_LIBS=”-L/usr/local/lib64/ -lnettle” HOGWEED_CFLAGS=”-I/usr/local/include” HOGWEED_LIBS=”-L/usr/local/lib64/ -lhogweed”
export LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/lib64/ LIBGNUTLS_CFLAGS=”-I/usr/local/include/” LIBGNUTLS_LIBS=”-L/usr/local/lib/ -lgnutls” LIBNL3_CFLAGS=”-I/usr/local/include” LIBNL3_LIBS=”-L/usr/local/lib/ -lnl-3 -lnl-route-3″

64bit
export LD_LIBRARY_PATH=/usr/lib/:/usr/lib64/ NETTLE_CFLAGS=”-I/usr/include/” NETTLE_LIBS=”-L/usr/lib64/ -lnettle” HOGWEED_CFLAGS=”-I/usr/include” HOGWEED_LIBS=”-L/usr/lib64/ -lhogweed”
export LD_LIBRARY_PATH=/usr/lib/:/usr/lib64/ LIBGNUTLS_CFLAGS=”-I/usr/include/” LIBGNUTLS_LIBS=”-L/usr/lib/ -lgnutls” LIBNL3_CFLAGS=”-I/usr/include” LIBNL3_LIBS=”-L/usr/lib/ -lnl-3 -lnl-route-3″

5、配置ocserv
建立ca認證和伺服器憑證(參考http://www.infradead.org/ocserv/manual.html#heading5)
certtool –generate-privkey –outfile ca-key.pem
cat << _EOF_ >ca.tmpl
cn = “stunnel.info VPN”
organization = “stunnel.info”
serial = 1
expiration_days = 365
ca
signing_key
cert_signing_key
crl_signing_key
_EOF_
certtool –generate-self-signed –load-privkey ca-key.pem –template ca.tmpl –outfile ca-cert.pem

certtool –generate-privkey –outfile server-key.pem
cat << _EOF_ >server.tmpl
cn = “stunnel.info VPN”
o = “stunnel”
serial = 2
expiration_days = 365
signing_key
encryption_key #only if the generated key is an RSA one
tls_www_server
_EOF_
certtool –generate-certificate –load-privkey server-key.pem –load-ca-certificate ca-cert.pem –load-ca-privkey ca-key.pem –template server.tmpl –outfile server-cert.pem

把認證複製到ocserv的配置目錄
mkdir -p /usr/local/etc/ocserv/ ; cp server-cert.pem /usr/local/etc/ocserv/ && cp server-key.pem /usr/local/etc/ocserv/</code>
複製設定檔樣本
<code>cp doc/sample.config /usr/local/etc/ocserv/ocserv.conf</code>
編輯設定檔
<code>vim /usr/local/etc/ocserv/ocserv.conf

修改如下:
auth = “plain[/usr/local/etc/ocserv/.passwd]”
#ocserv支援多種認證方式,這是內建的密碼認證,使用ocpasswd建立密碼檔案
#ocserv還支援認證認證,可以通過Pluggable Authentication Modules (PAM)使用radius等認證方式
server-cert = /usr/local/etc/ocserv/server-cert.pem
server-key = /usr/local/etc/ocserv/server-key.pem
#憑證路徑
max-same-clients = 10
#同一個使用者最多同時登陸數
run-as-group = nobody
ipv4-network = 192.168.10.0
#分配給VPN用戶端的IP段
dns = 8.8.8.8
dns = 8.8.4.4
#route = 192.168.1.0/255.255.255.0
#route = 192.168.5.0/255.255.255.0
#注釋掉這兩行。route參數留空表示所有流量均走VPN。
#ocserv可以給用戶端下發路由表。比如可以把公司內網IP段、所有國外IP走VPN出去。
#default-domain = example.com
#注釋掉這行。

建立認證用的使用者檔案
ocpasswd -c /usr/local/etc/ocserv/.passwd <username>

修改系統配置,允許轉寄
注意把網卡介面名稱改成你伺服器上對應的介面
sed -i ‘s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g’ /etc/sysctl.conf
sysctl -p
iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o venet0 -j MASQUERADE
iptables -A FORWARD -s 192.168.10.0/24 -j ACCEPT
#IP段和venet0介面要根據自己的情況修改

最後運行服務
/usr/local/sbin/ocserv -c /usr/local/etc/ocserv/ocserv.conf
在iOS上安裝Cisco AnyConnect即可串連伺服器
Android上也有Cisco AnyConnect(需要root),不過Android可選擇的太多,推薦Shadowsocks
Windows、MAC OS也有Cisco的官方用戶端

參考:
http://www.infradead.org/ocserv/manual.html
http://ttz.im/blog/2014/02/1131
http://www.cisco.com/web/CN/solutions/trends/byod_smart_solution/pdf/at_a_glance_c45_578609.pdf
http://botu.me/entry/install-ocserv-on-centos6.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.