centos6安装openvon+AD验证方法
第1步:安装centos6,并添加centos的升级镜像,添加epel镜像
首先备份/etc/yum.repos.d/CentOS-Base.repo
1 |
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup |
下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)
1 2 3 4 5 6 7 8 9 |
cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 然后下载epel库安装 <pre class="lang:sh decode:true ">wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uhv epel-release-6-5.noarch.rpm |
运行yum makecache生成缓存
如果出错,检查下163的镜像库是否有问题。
1 |
vim CentOS6-Base-163.repo |
将对应的addons内容注释掉,因为库还没出来,所以必须注释掉
1 2 3 4 5 6 7 |
#packages used/produced in the build but not released #[addons] #name=CentOS-$releasever - Addons - 163.com #baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons #gpgcheck=1 #gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 |
第2步,安装编译程序所需要的日常库
1 2 3 |
sudo -s LANG=C yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers |
下面安装openvpn及openvpn-auth-ldap
yum install openvpn openvpn-auth-ldap 安装完成后,开始调试openvpn和openvpn-auth-ldap
执行下面的操作
cp -R /usr/share/openvpn/easy-rsa//etc/openvpn/ 然后开始建立server的ca,key
1 2 |
cd /etc/openvpn/easy-rsa/2.0/ 编辑vars,按shit+g跳转到最下面,编辑成你需要的信息。 |
export KEY_COUNTRY="CN"
export KEY_PROVINCE="GD"
export KEY_CITY="GUANGZHOU"
export KEY_ORG="GZDC"
export KEY_EMAIL=FANGBO@GZDC.CN 然后指定编译源
1 2 |
source ./vars 下面开始生成ca证书 |
1 2 3 |
./clean-all ./build-ca ca 直接回车完成 |
再生成server.key
1 2 |
./build-key-server server 回车直到最后两项,按“Y”确认。 |
然后我们需要生成Diffie Hellman参数,这个需要一点时间的。
1 2 |
./build-dh 下面,我们还需要生成一个tls验证key |
1 2 |
openvpn --genkey --secret keys/ta.key 到这里先做个小结:我们生成的文件都放在/etc/openvpn/easy-rsa/2.0/keys/,记住,我们等会会用到这个路径。 |
下面再建立openvpn的配置文件,有两种方式:
1、将例子文档复制到openvpn目录下
1 |
cp /usr/share/doc/openvpn-2.1.4/sample-config-files/server.conf /etc/openvpn/ |
2、直接建立openvpn配置文档
1 |
vim /etc/openvpn/server.conf |
然后输入以下内容并保存。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
port 1194 proto udp dev tun #指定位置 ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt cert /etc/openvpn/easy-rsa/2.0/keys/server.crt key /etc/openvpn/easy-rsa/2.0/keys/server.key dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem tls-auth /etc/openvpn/easy-rsa/2.0/keys/ta.key 0 server 10.8.0.0255.255.255.0 push "redirect-gateway def1" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" push "dhcp-option DNS 10.8.0.1" client-to-client keepalive 10120 comp-lzo persist-key persist-tun client-cert-not-required username-as-common-name #这里是指定openvpn-auth-ldap.so这个插件 plugin /usr/lib64/openvpn/plugin/lib/openvpn-auth-ldap.so /etc/openvpn/auth/ldap.conf #log #日志存放目录 log openvpn.log status openvpn-status.log # Verbosity level. # 0 -- quiet except for fatal errors. # 1 -- mostly quiet, but display non-fatal network errors. # 3 -- medium output, good for normal operation. # 9 -- verbose, good for troubleshooting #日志级别 verb 3 |
3、下面再编辑ldap配置文件
1 |
vim /etc/openvpn/auth/ldap.conf |
输入下面信息,可按照你们自己AD的信息来修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<LDAP> # LDAP server URL URL ldap://gzdc.cn:389 #这里也可以填IP地址,若是IP地址,下面的DNS就不用做特别限定 # Bind DN (If your LDAP server doesn't support anonymous binds) BindDN "cn=digiwin,cn=Users,dc=gzdc,dc=cn" # Bind Password Password digiwin # Network timeout (in seconds) Timeout 60 # Enable Start TLS TLSEnable no # Follow LDAP Referrals (anonymously) #FollowReferrals no # TLS CA Certificate File #TLSCACertFile /usr/local/etc/ssl/ca.pem # TLS CA Certificate Directory #TLSCACertDir /etc/ssl/certs # Client Certificate and key # If TLS client authentication is required #TLSCertFile /usr/local/etc/ssl/client-cert.pem #TLSKeyFile /usr/local/etc/ssl/client-key.pem # Cipher Suite # The defaults are usually fine here # TLSCipherSuite ALL:!ADH:@STRENGTH </LDAP> <Authorization> # Base DN BaseDN "CN=Users,DC=gzdc,DC=cn" # User Search Filter SearchFilter "(&(sAMAccountName=%u))" # Require Group Membership RequireGroup false # Add non-group members to a PF table (disabled) #PFTable ips_vpn_users #<Group> # BaseDN "ou=Groups,dc=example,dc=com" # SearchFilter "(|(cn=developers)(cn=artists))" # MemberAttribute uniqueMember # # Add group members to a PF table (disabled) # #PFTable ips_vpn_eng #</Group> </Authorization> |
保存退出。
下面需要操作防火墙及设置IP转发。
先修改ip转发。
1 |
vim /etc/sysctl.conf |
将net.ipv4.ip_forward = 0修改为net.ipv4.ip_forward = 1
修改完成后检查一下
1 |
$sysctl -p |
#可检查自己是否成功,若下面的项则表示成功
1 2 3 4 5 6 7 |
net.ipv4.ip_forward =1 net.ipv4.conf.default.rp_filter =1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid =1 net.ipv4.tcp_syncookies =1 |
下面需要修改防火墙的端口设置及IP规则。
配置你的防火墙
1 |
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0:0 -j MASQUERADE |
#你的网卡借口,由于我的主机是VPS主机,所以网卡为venet0:0
1 |
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 你的服务器地址 |
#设置地址转发
service iptables save
#保存配置
service iptables restart
#接着重启防火墙 呵呵,到这一步,大家最容易忽视的地方在哪里?【如果之前你填写的AD服务器是IP地址,此步可省略】
DNS的指向,由于我们采用的是LDAP验证,那就必须能读取AD的信息,所以我们必须将服务器的DNS指向到AD服务器。
1 2 |
vim /etc/resolv.conf 保证第一个DNS服务器是AD服务器的DNS |
1 2 3 |
# Generated by NetworkManager search gzdc.cn #我的AD服务器DNS是以下地址, |
1 2 |
nameserver 172.16.70.20 保存退出之后,大家试验ping下域名服务器及ad服务器。 |
服务器的配置到此大致结束。
可以启动openvpn试试看。
1 2 3 |
service openvpn start 如果没什么遗漏,系统会顺利起来。 第三步,配置本地client端。 |
下载http://swupdate.openvpn.org/community/releases/openvpn-2.2.1-install.exe
在安装目录下有个config目录,
将服务器上了的ca.crt,ca.key,ta.key三个文件复制到config下。
新建一个文本文件,输入以下内容。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
client dev tun proto udp remote 192.168.70.30 1194 resolv-retry infinite nobind persist-key persist-tun ca ca.crt tls-auth ta.key 1 ns-cert-type server comp-lzo verb 3 auth-user-pass |
保存后,将后缀名.txt改成.ovpn
后续的,你就不要问我了,如果不会,请买块豆腐撞死!
拨上了吗? 此时你可以尝试下能不能ping通10.8.0.1
版权声明:
作者:心飞翔
链接:https://www.faystar.com/techshare/linux/51.html
来源:心飞翔
文章版权归作者所有,未经允许请勿转载。
test
admin@test