howtodownload

howtodownload
cach down

Thứ Bảy, 12 tháng 10, 2013

Cấu hình dịch vụ OpenVPN chứng thực OpenLDAP trên centos phần 1

Mô Hình:

Yêu cầu:Server đã cài DNS và LDAP.

I.Cài đặt openVPN:

Cài gói gcc,mak để biên dịch:

yum install gcc* make*
Download các gói thư viện:
Và download thêm:



Cài đặt các gói phụ thuộc:

#yum install rpm-build -y
#yum install autoconf.noarch -y
#yum install zlib-devel -y
#yum install pam-devel -y
#yum install openssl-devel -y
Cài đặt các gói rpm mà nãy bạn tải về ở trên , add vào kho lưu trữ trên centos của bạn:
rpmbuild --rebuild lzo-1.08-4.rf.src.rpm
rpm -Uvh /usr/src/redhat/RPMS/i386/lzo-*.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
Chú ý: Kiểm tra thật kỹ version centos la bao nhiêu bit: 64 bit thì chuyển "i386" thành "x86_64". Nếu không đúng sẽ không yum dc openvpn.
Cài đặt OpenVPN:

yum install openvpn -y
Cài xong thì nên coi xem đã cài dc chưa, nếu chưa có thì cài lại mấy gói trên cho đúng version.



II.Cấu hình Openvpn chứng thực từ OpenLDAP:

Download gói cần thiết cho quá trình chứng thực

#cd /tmp
#wget ftp://rpmfind.net/linux/epel/5/i386/...3.el5.i386.rpm
#rpm -ivh /tmp/openvpn-auth-ldap-2.0.3-3.el5.i386.rpm
# mkdir /etc/openvpn
#cp /usr/share/doc/openvpn-2.2.2/easy-rsa /etc/openvpn/ -r
#cd /etc/openvpn/easy-rsa/2.0/
Cấu hình CA:
chmod 755 *
vi vars


Tạo CA:

#source ./vars
#./vars
#./clean-all
#./build-ca
Đến đây bạn không có thay đổi gì trong file cấu hình thì cứ enter cho nó build key nha.



#./build-key-server server
Bước này chú ý: khi build thì enter khi nào hiện ra dòng [y/n] thì gõ y và enter để nó build key hoàn thiện nha.



Tạo Diffie Hellman ( DH ): băm keys

#./build-dh
# ls keys/
Ta có dc key( build làm sao phải có dc 1 đống key giống hình nha, ko đủ key thì tạo lại key khác):



Tiếp theo copy file sample và cấu hình openvpn:

#cp /usr/share/doc/openvpn-2.2.2/sample-config-files/server.conf /etc/openvpn/
#vi /etc/openvpn/server.conf
25 local 192.168.88.129 #ip mặt ngoài của server
32 port 1194 #port kết nối
36 proto udp #Giao thức
53 dev tun #dùng tunnel, nếu dùng theo bridge chọn dev tap0 và những config khác sẽ khác với tunnel
54 tun-mtu 1500
55 tun-mtu-extra 32
56 mssfix 1450
80 ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
81 cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
82 key /etc/openvpn/easy-rsa/2.0/keys/server.key # This file should be kept secret
90 dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
99 server 10.8.0.0 255.255.255.0 #ip ma server sẽ cấp cho vpn client
197 push "redirect-gateway def1"
200 push "dhcp-option DNS 10.20.0.200"
201 push "dhcp-option DNS 8.8.8.8"
229 keepalive 10 120
277 status server-tcp.log
289 log /var/log/openvpn.log
#thêm vào cuối file 2 dòng sau:
plugin /usr/lib/openvpn/plugin/lib/openvpn-auth-ldap.so /etc/openvpn/auth/auth-ldap.conf
client-cert-not-required
#mkdir /etc/openvpn/auth
#cp /usr/share/doc/openvpn-auth-ldap-2.0.3/auth-ldap.conf /etc/openvpn/auth/
#vi /etc/openvpn/auth/auth-ldap.conf
PHP Code:
<LDAP>
    # LDAP server URL
    URL        ldap://10.20.0.200:389

    # Bind DN (If your LDAP server doesn't support anonymous binds)
    # BindDN        uid=Manager,ou=People,dc=example,dc=com

    # Bind Password
    # Password    SecretPassword

    # Network timeout (in seconds)
    Timeout        15

    # Enable Start TLS
    TLSEnable    no

    # Follow LDAP Referrals (anonymously)
    #FollowReferrals yes

    # 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        "dc=conmotit,dc=com"
#"ou=Users,dc=conmotit,dc=com"
    # User Search Filter
    SearchFilter    "(&(uid=%u))"

    # Require Group Membership
    RequireGroup    false

    # Add non-group members to a PF table (disabled)
    #PFTable    ips_vpn_users

    #Group>
    #BaseDN        "ou=Groups,dc=,dc=com"
    #SearchFilter    "(|(cn=developers)(cn=artists))"
    #MemberAttribute    uniqueMember
        # Add group members to a PF table (disabled)
        #PFTable    ips_vpn_eng
    #/Group>
</Authorization>  
#service openvpn restart
#authconfig-tui


Cấu hình như dưới


III.Forwarding

#vi /etc/sysctl.conf

#sysctl -p (để cho các thông số có hiệu lực)
#echo 1 > /proc/sys/net/ipv4/ip_forward

Tắt tường lửa đi nha và cuối cùng chạy dòng dưới

#openvpn /etc/openvpn/server.conf
Chú ý: Nhiều bạn làm ko để ý phần quan trọng này (chạy dòng trên để yên đó và ko làm gì hết thì client mới connect dc nha)
Nhiều bạn ko chạy dòng đó nên nó cứ bị lỗi này 

1 nhận xét:

  1. anh ơi cho em hỏi chút đc không ạ? nếu tiện anh add skype em nha. phungduyhung1072

    Trả lờiXóa