tun
(برای تونلهای سطح IP) و tap
(برای تونلهای سطح Ethernet) پشتیبانی میشوند. در عمل، رابطهای tun
اغلب مورد استفاده قرار میگیرند زمانی که کلاینتهای VPN قرار باشد درون شبکه محلی سرور با استفاده از پل Ethernet تنظیم گردند.
openssl
پیادهسازی شده است.
$
make-cadir pki-falcot
$
cd pki-falcot
vars
file, which can be uncommented and edited:
$
vim vars
$
grep EASYRSA vars
export KEY_CONFIG=`$EASY_RSA/whichopensslcnf $EASY_RSA` export KEY_DIR="$EASY_RSA/keys" echo NOTE: If you run ./clean-all, I will be doing a rm -rf on $KEY_DIR export KEY_SIZE=2048 export KEY_EXPIRE=3650 export KEY_COUNTRY="FR" export KEY_PROVINCE="Loire" export KEY_CITY="Saint-Étienne" export KEY_ORG="Falcot Corp" export KEY_EMAIL="admin@falcot.com" export KEY_OU="Certificate authority" export KEY_NAME="Certificate authority for Falcot Corp" # If you'd like to sign all keys with the same Common Name, uncomment the KEY_CN export below # export KEY_CN="CommonName" $
keys/ca.crt
و keys/ca.key
ذخیره میشوند):
pki/ca.crt
and pki/private/ca.key
during this step). We can add the option nopass
to avoid entering a password each time the private key is used:
$
./easyrsa build-ca nopass
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating RSA private key, 2048 bit long modulus (2 primes) ......................................................................................+++++ ......................+++++ e is 65537 (0x010001) You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Common Name (eg: your user, host, or server name) [Easy-RSA CA]: CA creation complete and you may now import and sign cert requests. Your new CA certificate file for publishing is at: /home/roland/pki-falcot/pki/ca.crt
vpn.falcot.com
شناخته میشود؛ این نام برای فایلهای دیگری نیز استفاده شده است (keys/vpn.falcot.com.crt
برای گواهینامه عمومی و keys/vpn.falcot.com.key
برای کلید خصوصی آن):
$
./easyrsa gen-req vpn.falcot.com nopass
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating a RSA private key .................................................................................+++++ ........+++++ writing new private key to '/home/roland/pki-falcot/pki/private/vpn.falcot.com.key.E5c3RGJBUd' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Common Name (eg: your user, host, or server name) [vpn.falcot.com]: Keypair and certificate request completed. Your files are: req: /home/roland/pki-falcot/pki/reqs/vpn.falcot.com.req key: /home/roland/pki-falcot/pki/private/vpn.falcot.com.key $
./easyrsa sign-req server vpn.falcot.com
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 You are about to sign the following certificate. Please check over the details shown below for accuracy. Note that this request has not been cryptographically verified. Please be sure it came from a trusted source or that you have verified the request checksum with the sender. Request subject, to be signed as a server certificate for 1080 days: subject= commonName = vpn.falcot.com Type the word 'yes' to continue, or any other input to abort. Confirm request details:
yes
Using configuration from /home/roland/pki-falcot/pki/safessl-easyrsa.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :ASN.1 12:'vpn.falcot.com' Certificate is to be certified until Jun 14 10:44:44 2022 GMT (1080 days) Write out database with 1 new entries Data Base Updated Certificate created at: /home/roland/pki-falcot/pki/issued/vpn.falcot.com.crt $./easyrsa gen-dh
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating DH parameters, 2048 bit long safe prime, generator 2 This is going to take a long time […] DH parameters of size 2048 created at /home/roland/pki-falcot/pki/dh.pem
$
./build-key JoeSmith
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating a RSA private key ....+++++ ..............................+++++ writing new private key to '/home/roland/pki-falcot/pki/private/JoeSmith.key.mY21iP8ysv' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Common Name (eg: your user, host, or server name) [JoeSmith]: Keypair and certificate request completed. Your files are: req: /home/roland/pki-falcot/pki/reqs/JoeSmith.req key: /home/roland/pki-falcot/pki/private/JoeSmith.key
pki/ca.crt
) will be stored on all machines (both server and clients) as /etc/ssl/certs/Falcot_CA.crt
. The server's certificate is installed only on the server (pki/issued/vpn.falcot.com.crt
goes to /etc/ssl/vpn.falcot.com.crt
, and pki/private/vpn.falcot.com.key
goes to /etc/ssl/private/vpn.falcot.com.key
with restricted permissions so that only the administrator can read it), with the corresponding Diffie-Hellman parameters (pki/dh.pem
) installed to /etc/openvpn/dh.pem
. Client certificates are installed on the corresponding VPN client in a similar fashion.
/etc/openvpn/*.conf
. Setting up a VPN server is therefore a matter of storing a corresponding configuration file in this directory. A good starting point is /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz
, which leads to a rather standard server. Of course, some parameters need to be adapted: ca
, cert
, key
and dh
need to describe the selected locations (respectively, /etc/ssl/certs/Falcot_CA.crt
, /etc/ssl/vpn.falcot.com.crt
, /etc/ssl/private/vpn.falcot.com.key
and /etc/openvpn/dh.pem
). The server 10.8.0.0 255.255.255.0
directive defines the subnet to be used by the VPN; the server uses the first IP address in that range (10.8.0.1
) and the rest of the addresses are allocated to clients.
tun0
. اگرچه، فایروالها اغلب به شیوه مشابه رابطهای واقعی شبکه پیکربندی میشوند، که درست قبل از آغاز OpenVPN اتفاق میافتند. البته توصیه میشود که ابتدا یک رابط شبکه مجازی پایدار ایجاد گردد، سپس OpenVPN را مبتنی با آن تنظیم کرد. این کار امکان نامگذاری برای رابط را فراهم میآورد. برای اینکار، دستور openvpn --mktun --dev vpn --dev-type tun
یک رابط شبکه مجازی به نام vpn
از نوع tun
ایجاد میکند؛ این دستور به سادگی میتواند در یک اسکریپت پیکربندی فایروال یا یک دستور up
در فایل /etc/network/interfaces
قرار گیرد. فایل پیکربندی OpenVPN نیز مطابق آن باید بروزرسانی گردد، با استفاده از عبارتهای dev vpn
و dev-type tun
.
10.8.0.1
میتوانند به سرور متصل گردند. برای صادر کردن مجوز دسترسی کلاینتها به شبکه محلی (192.168.0.0/24)، نیاز است که عبارت push route 192.168.0.0 255.255.255.0
به فایل پیکربندی OpenVPN اضافه گردد تا کلاینتها به صورت خودکار به شبکه VPN موجود متصل گردند. علاوه بر این، رایانههای شبکه محلی نیاز دارند در رابطه با مسیریابی از طریق سرور VPN به آنها اطلاعرسانی گردد (زمانی که سرور VPN به gateway متصل باشد این اتفاق میافتد). همین طور، سرور VPN میتواند به منظور ماسکگذاری IP پیکربندی گردد (
قسمت 10.1, “Gateway”
را مشاهده کنید).
/etc/openvpn/
است. یک پیکربندی ساده میتواند مانند /usr/share/doc/openvpn/examples/sample-config-files/client.conf
باشد. عبارت remote vpn.falcot.com 1194
نشانی و درگاه سرور OpenVPN را مشخص میکند؛ ca
، cert
و key
برای مشخصکردن محل فایلهای کلید باید تعریف شوند.
AUTOSTART
directive to none
in the /etc/default/openvpn
file. Starting or stopping a given VPN connection is always possible with the commands systemctl start openvpn@name
and systemctl stop openvpn@name
(where the connection name matches the one defined in /etc/openvpn/name.conf
).
tun*
) در هر دو سمت ارتباط SSH وجود دارد و این رابطهای مجازی میتوانند همانند رابطهای فیزیکی پیکربندی گردند. سیستم تونلکشی ابتدا باید با تنظیم PermitTunnel
به “yes” در فایل پیکربندی سرور SSH (/etc/ssh/sshd_config
) فعال گردد. هنگام برقراری ارتباط SSH، ایجاد یک تونل باید به صورت اختصاصی و با گزینه -w any:any
بیان شود (any
میتواند با شماره دستگاه tun
مورد نظر جایگزین گردد). این امر نیازمند داشتن دسترسی مدیریتی برای کاربر در هر دو سمت است، همانطور که برای ایجاد دستگاه شبکه مورد نیاز است (به عبارت دیگر، ارتباط باید از طریق root برقرار شود).
/etc/ipsec-tools.conf
شامل پارامترهای IPsec tunnels (یا Security Associations در واژگان IPsec) است که میزبان با آن ارتباط دارد؛ اسکریپت /etc/init.d/setkey
روشی برای آغاز و پایان یک تونل فراهم میکند (هر تونل یک پیوند امن به میزبان دیگری است که به شبکه خصوصی مجازی متصل است). این فایل میتواند به صورت دستی از مستندات موجود در صفحه راهنمای setkey(8) ساخته شود. البته، نوشتن پارامترهای تمام میزبانها در یک مجموعه بزرگ از رایانهها به آرامی به فرآیندی دشوار تبدیل میشود، چرا که تعداد تونلها به سرعت افزایش مییابند. نصب یک فرآیند پسزمینه IKE (که مخفف IPsec Key Exchange است) مانند racoon یا strongswan به سادهتر شدن کار مدیریت آنها به صورت مرکزی و امنتر شدن آنها با بایگانیهای متعدد منجز میشود.
/etc/ppp/options.pptp
، /etc/ppp/peers/falcot
، /etc/ppp/ip-up.d/falcot
و /etc/ppp/ip-down.d/falcot
.
مثال 10.2. فایل /etc/ppp/options.pptp
# PPP options used for a PPTP connection lock noauth nobsdcomp nodeflate
مثال 10.3. فایل /etc/ppp/peers/falcot
# vpn.falcot.com is the PPTP server pty "pptp vpn.falcot.com --nolaunchpppd" # the connection will identify as the "vpn" user user vpn remotename pptp # encryption is needed require-mppe-128 file /etc/ppp/options.pptp ipparam falcot
pptpd
سرور PPTP برای لینوکس است. فایل اصلی پیکربندی آن، /etc/pptpd.conf
، نیاز به تغییرات اندکی دارد: localip (نشانی محلی) و remoteip (نشانی راهدور). در نمونه زیر، سرور PPTP همیشه از نشانی 192.168.0.199
استفاده میکند و کلاینتها نیز نشانی خود را بین بازه 192.168.0.200
تا 192.168.0.250
دریافت میکنند.
مثال 10.6. فایل /etc/pptpd.conf
# TAG: speed # # Specifies the speed for the PPP daemon to talk at. # speed 115200 # TAG: option # # Specifies the location of the PPP options file. # By default PPP looks in '/etc/ppp/options' # option /etc/ppp/pptpd-options # TAG: debug # # Turns on (more) debugging to syslog # # debug # TAG: localip # TAG: remoteip # # Specifies the local and remote IP address ranges. # # You can specify single IP addresses separated by commas or you can # specify ranges, or both. For example: # # 192.168.0.234,192.168.0.245-249,192.168.0.254 # # IMPORTANT RESTRICTIONS: # # 1. No spaces are permitted between commas or within addresses. # # 2. If you give more IP addresses than MAX_CONNECTIONS, it will # start at the beginning of the list and go until it gets # MAX_CONNECTIONS IPs. Others will be ignored. # # 3. No shortcuts in ranges! ie. 234-8 does not mean 234 to 238, # you must type 234-238 if you mean this. # # 4. If you give a single localIP, that's ok - all local IPs will # be set to the given one. You MUST still give at least one remote # IP for each simultaneous client. # #localip 192.168.0.234-238,192.168.0.245 #remoteip 192.168.1.234-238,192.168.1.245 #localip 10.0.1.1 #remoteip 10.0.1.2-100 localip 192.168.0.199 remoteip 192.168.0.200-250
/etc/ppp/pptpd-options
است. پارامترهای مهم عبارتند از نام سرور (pptp
)، نام دامنه (بشمزخف.زخپ
) و نشانیهای IP برای سرورهای DNS و WINS.
مثال 10.7. فایل /etc/ppp/pptpd-options
## turn pppd syslog debugging on #debug ## change 'servername' to whatever you specify as your server name in chap-secrets name pptp ## change the domainname to your local domain domain falcot.com ## these are reasonable defaults for WinXXXX clients ## for the security related settings # The Debian pppd package now supports both MSCHAP and MPPE, so enable them # here. Please note that the kernel support for MPPE must also be present! auth require-chap require-mschap require-mschap-v2 require-mppe-128 ## Fill in your addresses ms-dns 192.168.0.1 ms-wins 192.168.0.1 ## Fill in your netmask netmask 255.255.255.0 ## some defaults nodefaultroute proxyarp lock
vpn
و گذرواژه مربوط به آن در فایل /etc/ppp/chap-secrets
است. بر خلاف مواقعی که کاراکتر ستاره (*
) کار میکرد، نام سرور مشخصا باید در این قسمت درج شود. علاوه بر این، کلاینتهای PPTP در ویندوز خود را به صورت DOMAIN\\USER
معرفی میکنند به جای اینکه تنها نام کاربری را نشان دهند. به همین دلیل است که فایل به کاربر FALCOT\\vpn
اشاره کرده است. همچنین امکان اختصاص نشانیهای IP انفرادی برای هر کاربر وجود دارد؛ یک کاراکتر ستاره در این قسمت به معنای استفاده از نشانیهای پویا است.