Ubuntu下安装与配置openvpn
1. 服务器端
(1) 在linux终端上运行apt-get install openvpn
(2) 复制配置文件到/etc下: cp -R /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn/
(3) 修改var文件:vim /etc/openvpn/easy-rsa/2.0/vars。其实也可以不修改,但是为了后续步骤能够一路enter,所以就先在这里修改下吧(随便填)。主要是要修改末尾的几行。
export KEY_COUNTRY=" CN"
export KEY_PROVINCE=" Beijing"
export KEY_CITY="Beijing "
export KEY_ORG=" FT"
export KEY_EMAIL="dadashd@qq"
=号后边就自己填入吧,我不知道大小写有没有影响,为了以防万一,还是按照它默认的格式来写吧。编辑完之后要记得保存。
export KEY_PROVINCE=" Beijing"
export KEY_CITY="Beijing "
export KEY_ORG=" FT"
export KEY_EMAIL="dadashd@qq"
=号后边就自己填入吧,我不知道大小写有没有影响,为了以防万一,还是按照它默认的格式来写吧。编辑完之后要记得保存。
(4) 产生证书
#cd /etc/openvpn/easy-rsa/2.0/
#chown -R root:admin .
#chmod g+w .
#chown -R root:admin .
#chmod g+w .
#source ./vars
#./clean-all
#./build-ca 一路回车,遇到要选择y/n时,选择y,以下三个步骤都相同
# ./build-key-server server
# ./build-key client
#./build-dh
新产生的证书可以在/etc/openvpn/easy-rsa/2.0/keys/目录下到。
(5)进行服务器端文件配置
首先需要复制一份配置样本,然后再在这个基础上进行修改:
#cp /usr/share/doc/openvpn/examples/f.gz /etc/openvpn/
#cd /etc/openvpn/
#f.gz
这样就会解压出一个f文件,f编辑
# Which local IP address should OpenVPN
# listen on? (optional)
xx #这里的ip用你自己机器上网卡ip
# listen on? (optional)
xx #这里的ip用你自己机器上网卡ip
# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194 #设置端口,注意要与客户端配置一致ubuntu vim命令
# number for each one. You will need to
# open up this port on your firewall.
port 1194 #设置端口,注意要与客户端配置一致ubuntu vim命令
# TCP or UDP server?
;proto tcp
proto udp #使用的协议
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap
# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key). Each client
# and the server must have their own cert and
# key file. The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
#下边三行注意要写对路径
ca easy-rsa/2.0/
cert easy-rsa/2.0/
key easy-rsa/2.0/keys/server.key
ca easy-rsa/2.0/
cert easy-rsa/2.0/
key easy-rsa/2.0/keys/server.key
# Diffie hellman parameters.
# Generate your own with:
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh easy-rsa/2.0/keys/dh1024.pem #注意路径
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh easy-rsa/2.0/keys/dh1024.pem #注意路径
# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0 #虚拟网卡上的ip地址段
# Maintain a record of client <-> virtual IP address
# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
;push "redirect-gateway def1 bypass-dhcp"
# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses. CAVEAT:
# openvpn/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.
;push "dhcp-option DNS 208.67.222.222"
;push "dhcp-option DNS 208.67.220.220"
# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
client-to-client #客户端到客户端
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
client-to-client #客户端到客户端
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论