📄 openvpn.8
字号:
every packet on the control channel is authenticated by anHMAC signature and a unique ID for replay protection.This signature will also help protect against DoS (Denial of Service) attacks.An important rule of thumb in reducing vulnerability to DoS attacks is tominimize the amount of resources a potential, but as yet unauthenticated,client is able to consume..B --tls-authdoes this by signing every TLS control channel packet with an HMAC signature,including packets which are sent before the TLS level has had a chanceto authenticate the peer.The result is that packets withoutthe correct signature can be dropped immediately upon reception,before they have a chance to consume additional system resourcessuch as by initiating a TLS handshake..B --tls-authcan be strengthened by adding the.B --replay-persistoption which will keep OpenVPN's replay protection statein a file so that it is not lost across restarts.It should be emphasized that this feature is optional and that thepassphrase file used with.B --tls-authgives a peer nothing more than the power to initiate a TLShandshake. It is not used to encrypt or authenticate any tunnel data..TP.B --askpassGet PEM password from controlling tty before we daemonize. For the extremelysecurity conscious, it is possible to protect your private key witha password. Of course this means that every time the OpenVPNdaemon is started you must be there to type the password. The.B --askpassoption allows you to start OpenVPN from the command line. It willquery you for a password before it daemonizes. To protect a privatekey with a password you should omit the.B -nodesoption when you use the.B opensslcommand line tool to manage certificates and private keys..TP.B --tls-verify cmdExecute shell command.B cmdto verify the X509 name of apending TLS connection that has otherwise passed all othertests of certification..B cmdshould return 0 to allow the TLS handshake to proceed, or 1 to fail..B cmdis executed as.B cmd certificate_depth X509_NAME_onelineNote that.B cmdcan be a shell command with multiple arguments, in whichcase all OpenVPN-generated arguments will be appendedto.B cmdto build a command line which will be passed to the script.This feature is useful if the peer you want to trust has a certificatewhich was signed by a certificate authority who also signed a zillionother certificates. In this case you want to be selective about whichpeer certificate you accept. This feature allows you to write a scriptwhich will test the X509 name on a certificate and decide whether ornot it should be accepted. For a simple perl script which will testthe common name field on the certificate, see the file.B verify-cnin the OpenVPN distribution..TP.B --disable-occDisable options compatibility check between peers. This is designedto circumvent OpenVPN's normal options compatibility check inTLS mode. Use of this option is discouraged, but is provided asa temporary fix in situations where a recent version of OpenVPN mustconnect to an old version..SS SSL Library information:.TP.B --show-ciphersShow all cipher algorithms to use with the.B --cipheroption..TP.B --show-digestsShow all message digest algorithms to use with the.B --authoption..TP.B --show-tlsShow all TLS ciphers (TLS used only as a control channel). The TLSciphers will be sorted from highest preference (most secure) tolowest..SS Generate a random key:Used only for non-TLS static key encryption mode..TP.B --genkeyGenerate a random key to be used as a shared secret,for use with the.B --secretoption. This file must be shared with thepeer over a pre-existing secure channel such as.BR scp (1)..TP.B --secret fileWrite key to.B file..SS TUN/TAP persistent tunnel config mode:Available with linux 2.4.7+. These options comprise a standalone modeof OpenVPN which can be used to create and delete persistent tunnels..TP.B --mktunCreate a persistent tunnel. Normally TUN/TAP tunnels exist only forthe period of time that an application has them open. This optiontakes advantage of the TUN/TAP driver's ability to build persistenttunnels that live through multiple instantiations of OpenVPN and dieonly when they are deleted or the machine is rebooted.One of the advantages of persistent tunnels is that they eliminate theneed for separate.B --upand.B --downscripts to run the appropriate.BR ifconfig (8)and.BR route (8)commands. These commands can be placed in the the same shell scriptwhich starts or terminates an OpenVPN session.Another advantage is that open connections through the TUN/TAP-based tunnelwill not be reset if the OpenVPN peer restarts. This can be useful toprovide uninterrupted connectivity through the tunnel in the event of a DHCPreset of the peer's public IP address (see the.B --ipchangeoption above).One disadvantage of persistent tunnels is that it is harder to automaticallyconfigure their MTU value (see.B --udp-mtuand.B --tun-mtuabove)..TP.B --rmtunRemove a persistent tunnel..TP.B --dev tunX | tapXTUN/TAP device.SH SIGNALS.TP.B SIGHUPCause OpenVPN to close all TUN/TAP andnetwork connections,restart, re-read the configuration file (if any),and reopen TUN/TAP and network connections..TP.B SIGUSR1Like .B SIGHUP,except don't re-read configuration file, and possibly don't close and reopen TUN/TAPdevice, re-read key files, preserve local IP address/port, or preserve most recently authenticatedremote IP address/port based on.B --persist-tun, --persist-key, --persist-local-ip,and.B --persist-remote-ipoptions respectively (see above).This signal may also be internally generated by a timeout condition, governedby the.B --ping-restartoption.This signal, when combined with.B --persist-remote-ip,may besent when the underlying parameters of the host's network interface changesuch as when the host is a DHCP client and is assigned a new IP address.See.B --ipchangeabove for more information..TP.B SIGUSR2Causes OpenVPN to display its current statistics (to the syslogfile if.B --daemonis used, or stdout otherwise)..TP.B SIGINT, SIGTERMCauses OpenVPN to exit gracefully..SH TUN/TAP DRIVER SETUPIf you are running Linux 2.4.7 or higher, you probably have the TUN/TAP driveralready installed. If so, there are still a few things you need to do:Make device:.B mknod /dev/net/tun c 10 200Load driver:.B modprobe tunIf you have Linux 2.2 or earlier, you should obtain version 1.1 of theTUN/TAP driver from.I http://vtun.sourceforge.net/tun/and follow the installation instructions..SH EXAMPLESPrior to running these examples, you should have OpenVPN installed on twomachines with network connectivity between them. If you have notyet installed OpenVPN, consult the INSTALL file included in the OpenVPNdistribution..SS TUN/TAP Setup:If you are using Linux 2.4 or higher,make the tun device node and load the tun module:.IP.B mknod /dev/net/tun c 10 200.LP.IP.B modprobe tun.LPIf you installed from RPM, the.B mknodstep may be omitted, because the RPM install does that for you.If you have Linux 2.2, you should obtain version 1.1 of theTUN/TAP driver from.I http://vtun.sourceforge.net/tun/and follow the installation instructions.For other platforms, consult the INSTALL file at.I http://openvpn.sourceforge.net/install.htmlfor more information..SS Firewall Setup:If firewalls exist betweenthe two machines, they should be set to forward UDP port 5000in both directions. If you do not have control over the firewallsbetween the two machines, you may still be able to use OpenVPN by adding.B --ping 15to each of the.B openvpncommands used below in the examples (this will cause each peer to send outa UDP ping to its remote peer once every 15 seconds which will cause manystateful firewalls to forward packets in both directionswithout an explicit firewall rule).If you are using a Linux iptables-based firewall, you may need to enterthe following command to allow incoming packets on the TUN device:.IP.B iptables -A INPUT -i tun+ -j ACCEPT.LPSee the firewalls section below for more information on configuring firewallsfor use with OpenVPN..SS VPN Address Setup:For purposesof our example, our two machines will be called.B may.kgand.B june.kg.If you are constructing a VPN over the internet, then replace.B may.kgand.B june.kgwith the internet hostname or IP address that each machine will useto contact the other over the internet.Now we will choose the tunnel endpoints. Tunnel endpoints areprivate IP addresses that only have meaning in the context ofthe VPN. Each machine will use the tunnel endpoint of the othermachine to access it over the VPN. In our example,the tunnel endpoint for may.kgwill be 10.4.0.1 and for june.kg, 10.4.0.2.Once the VPN is established, you have essentiallycreated a secure alternate path between the two hostswhich is addressed by using the tunnel endpoints. You cancontrol which networktraffic passes between the hosts (a) over the VPN or (b) independently of the VPN, by choosing whether to use(a) the VPN endpoint address or (b) the public internet address,to access the remote host. For example if you are on may.kg and you wish to connect to june.kgvia.B sshwithout using the VPN (since.B sshhas its own built-in security) you would use the command.B ssh june.kg.However in the same scenario, you could also use the command.B telnet 10.4.0.2to create a telnet session with june.kg over the VPN, that woulduse the VPN to secure the session rather than.B ssh.You can use any address you wish for thetunnel endpointsbut make sure that they are private addresses(such as those that begin with 10 or 192.168) and that they arenot part of any existing subnet on the networks ofeither peer. If you use an address that is part ofyour local subnet for either of the tunnel endpoints,you will get a weird feedback loop..SS Example 1: A simple tunnel without security.LPOn may:.IP.B openvpn --remote june.kg --dev tun1 --ifconfig 10.4.0.1 10.4.0.2 --verb 9.LPOn june:.IP.B openvpn --remote may.kg --dev tun1 --ifconfig 10.4.0.2 10.4.0.1 --verb 9.LPNow verify the tunnel is working by pinging across the tunnel..LPOn may:.IP.B ping 10.4.0.2.LPOn june:.IP.B ping 10.4.0.1.LPThe.B --verb 9option will produce verbose output, similar to the.BR tcpdump (8)program. Omit the.B --verb 9option to have OpenVPN run quietly..SS Example 2: A tunnel with static-key security (i.e. using a pre-shared secret)First build a static key on may..IP.B openvpn --genkey --secret key.LPThis command will build a random key file called.B key(in ascii format).Now copy.B keyto june over a secure medium such as byusing the.BR scp (1)program..LPOn may:.IP.B openvpn --remote june.kg --dev tun1 --ifconfig 10.4.0.1 10.4.0.2 --verb 5 --secret key.LPOn june:.IP.B openvpn --remote may.kg --dev tun1 --ifconfig 10.4.0.2 10.4.0.1 --verb 5 --secret key.LPNow verify the tunnel is working by pinging across the tunnel..LPOn may:.IP.B ping 10.4.0.2.LPOn june:.IP.B ping 10.4.0.1.SS Example 3: A tunnel with full TLS-based securityFor this test, we will designate.B mayas the TLS client and.B juneas the TLS server..I Note that client or server designation only has meaning for the TLS subsystem. It has no bearing on OpenVPN's peer-to-peer, UDP-based communication model.First, build a separate certificate/key pairfor both may and june (see above where.B --certis discussed for more info). Then constructDiffie Hellman parameters (see above where.B --dhis discussed for more info). You can also use theincluded test files client.crt, client.key,server.crt, server.key and tmp-ca.crt.The .crt files are certificates/public-keys, the .keyfiles are private keys, and tmp-ca.crt is a certificationauthority who has signed bothclient.crt and server.crt. For Diffie Hellmanparameters you can use the included file dh1024.pem..I Note that all client, server, and certificate authority certificates and keys included in the OpenVPN distribution are totally insecure and should be used for testing only..LPOn may:.IP.B openvpn --remote june.kg --dev tun1 --ifconfig 10.4.0.1 10.4.0.2 --tls-client --ca tmp-ca.crt --cert client.crt --key client.key --reneg-sec 60 --verb 5.LPOn june:.IP.B openvpn --remote may.kg --dev tun1 --ifconfig 10.4.0.2 10.4.0.1 --tls-server --dh dh1024.pem --ca tmp-ca.crt --cert server.crt --key server.key --reneg-sec 60 --verb 5.LPNow verify the tunnel is working by pinging across the tunnel..LPOn may:.IP.B ping 10.4.0.2.LPOn june:.IP.B ping 10.4.0.1.LPNotice the.B --reneg-sec 60option we used above. That tells OpenVPN to renegotiatethe data channel keys every minute.Since we used.B --verb 5above, you will see status information on each new key negotiation.For production operations, a key renegotiation interval of 60 secondsis probably too frequent. Omit the.B --reneg-sec 60option to use OpenVPN's default key renegotiation interval of one hour..SS Routing:Assuming you can ping across the tunnel,the next step is to route a real subnet overthe secure tunnel. Suppose that may and j
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -