|
That's not a published item! You are not allowed to see the content of this item!
[ Source ]
create a secure virtual private network with openvpn
Created: 2007-11-28 23:19:00
Modified: 2009-04-25 13:34:00 Categories: tools server security network internet debian Keywords: vpn openvpn virtual private network Description: With openvpn you can easy create a very secure virtual network. Table Of ContentsIntroductionWith When setting up openvpn, you can choice about two different ways how the server will act. You can setup one client to one client. This will be ideal to create some bridge between two trusted network located at a different location. Or to setup a server who may receive different openvpn client connections. Installation and setupAt the time of writing this article, openvpn version For the server and client side, the install and the questions during the install are the same. aptitude install openvpn During the install, you will be asked for If you accept here, the package will make a special device called
/dev/net/tun for openvpn's use. If you refuse, the device won't be
made now. Read README.Debian for details on how to make it. If you
are using devfs refuse here.
Would you like a TUN/TAP device to be created?
<Yes> <No>Select Then you get the question: In some cases you may be upgrading openvpn in a remote server using a
VPN to do so. The upgrade process stops the running daemon before
installing the new version, in that case you may lose your connection,
the upgrade may be interrupted, and you may not be able to reconnect to
the remote host.
Unless you do your upgrades locally, it is advised NOT to stop
openvpn before it gets upgraded. The installation process will
restart it once it's done.
This option will take effect in your next upgrade.
Would you like to stop openvpn before it gets upgraded?
<Yes> <No>Select Note that i don't got these questions when installing openvpn om my Debian Etch and Lenny box anymore! It seems that some things have changed. You can get the latest question with "dpkg-reconfigure openvpn". One server, one clientCreating the static.key file: cd /etc/openvpn openvpn --genkey --secret static.key Copy this file On server side, create a file dev tun0 ifconfig 10.9.8.1 10.9.8.2 secret static.key # Enable compression the VPN link # must be enabled on both sides comp-lzo # 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 The client is another computer on another network. A computer on the other side of the world who has also an internet connection. On the client side create the file # The remote is the ip (or hostname) of the gateway remote 84.198.69.134 # set float if the gateway get's a dynamic IP float dev tun0 ifconfig 10.9.8.2 10.9.8.1 secret static.key # Enable compression the VPN link # must be enabled on both sides comp-lzo # 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 The routing table needs to be adjusted so that all the data won't pass to our
old default gateway but to the new gateway point. Issue the command This output Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.9.8.1 * 255.255.255.255 UH 0 0 0 tun0 localnet * 255.255.255.0 U 0 0 0 eth3 default moon.pinguin 0.0.0.0 UG 0 0 0 eth3 Remove the default (old) route: route del default Add the new route: route add default gw 10.9.8.1 See the modified routing table. Issue the command Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.9.8.1 * 255.255.255.255 UH 0 0 0 tun0 localnet * 255.255.255.0 U 0 0 0 eth3 default 10.9.8.1 0.0.0.0 UG 0 0 0 tun0 On the server side, the firewall needs to be adjusted aswell. For iptables use the following commands: iptables -A INPUT -i tun+ -j ACCEPT iptables -A INPUT -i $INTDEV -p UDP --dport 1194 -j ACCEPT If you want to be able to ping, you must allow iptable too: ## Set ICMP open to the internet tune0 $IPTABLES -A INPUT -i tun0 -p ICMP -j ACCEPT $IPTABLES -A OUTPUT -o tun0 -p ICMP -j ACCEPT # ICMP naar internet filteren $IPTABLES -A INPUT -i tune0 -p ICMP --icmp-type 0 -j ACCEPT $IPTABLES -A INPUT -i tune0 -p ICMP --icmp-type 3 -j ACCEPT $IPTABLES -A INPUT -i tune0 -p ICMP --icmp-type 5 -j ACCEPT $IPTABLES -A INPUT -i tune0 -p ICMP --icmp-type 11 -j ACCEPT Start openvpn on both side with the follow command: openvpn --config /etc/openvpn/tun0.conf One server, many clients (routed setup)We should first copy the key generator somewhere at a secure place. This will avoid to loose the config and keys if we later remove or upgrade the package: We first create the ca keys: mkdir /etc/openvpn_keys cp -r /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn/ cd /etc/openvpn/easy-rsa Edit the export KEY_COUNTRY=BE export KEY_PROVINCE=Vlaams-Brabant export KEY_CITY=Halle export KEY_ORG="DVM@Home" export KEY_EMAIL="david.van.mosselbeen@gmail.com" Now let start the process: source ./vars ./clean-all ./build-ca As we filled the vars file, some values should not be entered twice during the ./build-ca. Just the Organizational Unit Name (where i filled "IT"), Common Name (eg, your name or your server's hostname) []: dvm.zapto.org We now create the certificates and keys: ./build-key-server server Again as we did with the ./build-ca, just that you may fill in some cool challenge password. And had need to manually fill in the company name (DVM@Home). Respond yes to sign the certificate and commit. We now need to create the keys for the clients: ./build-key myClient1Hostname ./build-key myClient2Hostname ... Note that each client needs to have his own common name. So the CN for If later, you need to create an additional key for a client: cd /etc/openvpn/easy-rsa source ./vars ./build-key aNewClient If you have created the client keys on name of the hostname, don't forget to adjust the above line. Generate Diffie Hellman parameters: ./build-dh Note that this command take a very long time, especially because of the length of the 2048 bit key. This took around 20 minutes on a P3 664MHz. We should now copy some keys to some clients, here's the list with they usage:
On server side, copy the needed files from the keys directory where we have
create the certifications On the client side, copy the needed files from the server where we have create
the certifications files On server side, copy the default config file: zcat /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz \ > /etc/openvpn/server.conf On client side, copy the default config file: cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf \ /etc/openvpn/ Adjust the config file on server and client side. On the client side i had need
to add a line with as content Note that the firewall needs to be adjusted, like the many-clients to one server don't use the same network setup. On server side, i took a copy of good working "client.conf", so that in the future, if a new client needs to have a VPN connection, i first create the client keys and provide a modified version of the client.conf from the server. As in the client.conf file we just need to change two lines referencing to the client keys. Testing if the vpn workYou should now start the openvpn client on server side first: For both server and client, openvpn --config /etc/openvpn/server.conf And then on the client: openvpn --config /etc/openvpn/client.conf If you are running the If you are running the FirewallingBefore everything works like expected, even a ping, the firewalls needs to be
configured on server and client side so that it permit the vuurmuurI use vuurmuur to manage the iptables firewall on
my gateway. Here's an overview of the Server side - One server, one clientNote that the following vuurmuur firewall config is for the one-client to one server setup on server side. I use vuurmuur to manage the iptables firewall on
my gateway. Here's an overview of the Note that the following vuurmuur firewall config is for the one-client to one server setup. I first created an interface called tun0b with ip I added a host in this new As rules i have set: | 61 ----------------------------[ Openvpn ]----------------------------- | | [x] 62 Accept openvpn local.ptp-vpn firewall(any) log,loglimit="| | [x] 63 Accept ping local.ptp-vpn firewall(any) log,loglimit="| | [x] 64 Accept http local.ptp-vpn world.inet log,loglimit="| | [x] 65 Accept ssh local.ptp-vpn world.inet log,loglimit="| | [x] 66 Snat any local.ptp-vpn world.inet - | | 67 -------------------------------------------------------------------- | *Note that you may disable the interface Server side - One server, many clientsNote that the following vuurmuur firewall config is for the one server with many clients setup on server side. I first created an interface called tun0b with ip I added a host in this new | 71 ------------------[ one server multiples clients ]------------------ | | [x] 72 Accept openvpn any firewall(any) log,logprefix=| | [x] 73 Accept ping local.openvpn firewall(any) log,loglimit="| | 74 -------------------[ Access local lan from vpn ]-------------------- | | [x] 75 Accept ping local.openvpn local.lan log,loglimit="| | [x] 76 Accept ping local.openvpn world.inet log,loglimit="| | [x] 77 Accept http local.openvpn world.inet comment="Acces| | [x] 78 Accept https local.openvpn world.inet comment="Acces| | [x] 79 Accept http local.openvpn local.lan comment="Acces| | [x] 80 Accept ssh local.openvpn local.lan - | | [ ] 81 Accept ssh local.openvpn firewall(any) log,logprefix=| | [x] 82 Accept ldap local.openvpn local.lan - | | [x] 83 Accept imap local.openvpn local.lan - | | [x] 84 Accept imaps local.openvpn local.lan - | | [x] 85 Accept smtp local.openvpn local.lan - | | [x] 86 Accept portmap local.openvpn local.lan - | | [x] 87 Accept nfs local.openvpn local.lan - | | [x] 88 Accept rpc local.openvpn local.lan - | | [x] 89 Accept samba local.openvpn local.lan - | | [ ] 90 Accept any local.openvpn local.lan log,loglimit="| | [x] 91 Snat any local.openvpn world.inet - | | 92 ------[ Allow local.lan clients reach local.openvpn clients ]------- | | [x] 93 Accept ping local.lan local.openvpn log,loglimit="| | [x] 94 Accept ssh local.lan local.openvpn log,loglimit="| | [x] 95 Accept ident local.lan local.openvpn - | | 96 -------------------------------------------------------------------- | *Note that you may disable the interface Client sideOn client side you may also use vuurmuur and setup it up to your needs. Vuurmuur is straightforward and isn't hard/complicated to use. Give some time to setup it correctly. Or just some little shell script that let all in and out. Trust me, this isn't secure at all!!! At all, why do you use a encrypted secured manner to connect to your LAN?? You are warned, use this at your own risk!!! Create a file called somethings like
Then followed by and tune up to your needs!: # This script is especially made for use with openvpn. It open ALL and let # EVERYTHINGS in and out, use at your own risk!!! ### # IPTABLES="/sbin/iptables" TUN="tun0" INTDEV="wlan0" OPENVPNPORT=1194 PROTOCOL=UDP # Flush all previous rules $IPTABLES -F ## Open hole!! # Let everything in and out!!! #$IPTABLES -A INPUT -j ACCEPT #$IPTABLES -A OUTPUT -j ACCEPT #$IPTABLES -A FORWARD -j ACCEPT # Let some openvpn specifiq stuff pass $IPTABLES -A INPUT -i tun+ -j ACCEPT $IPTABLES -A OUTPUT -o tun+ -j ACCEPT $IPTABLES -A INPUT -i $INTDEV -p $PROTOCOL --dport $OPENVPNPORT -j ACCEPT $IPTABLES -A OUTPUT -p $PROTOCOL --dport $OPENVPNPORT -j ACCEPT # Permit ping ## Set ICMP open to the internet tune0 $IPTABLES -A INPUT -i $TUN -p ICMP -j ACCEPT $IPTABLES -A OUTPUT -o $TUN -p ICMP -j ACCEPT # ICMP naar internet filteren $IPTABLES -A INPUT -i $TUN -p ICMP --icmp-type 0 -j ACCEPT $IPTABLES -A INPUT -i $TUN -p ICMP --icmp-type 3 -j ACCEPT $IPTABLES -A INPUT -i $TUN -p ICMP --icmp-type 5 -j ACCEPT $IPTABLES -A INPUT -i $TUN -p ICMP --icmp-type 11 -j ACCEPT Or somethings more realist could be:
Set this file now as executable: chmod +x unsecure_openvpn_firewall_script.sh And now each time before you start your openvpn connection, start this script
as root user first. You should execute somethings like See the firewall script provided with You can now start the openvpn connection manually with: openvpn --config /etc/openvpn/client.conf Certificates revocation listAt some point, you want to reject some certification. This could be because you know that a particular client certification got compromised. If you want to be able to reject some certification, you need to create a certification revocation list. As first thing to do, we need to specify in the openvpn server configuration to check revoked certificates from a particular file: echo " # Revoked certificate list crl-verify /etc/openvpn/keys/certification_revocation_list.pem" >> /etc/openvpn/server.conf We can now create an empty revocation file with: # First load (source) the needed config cd /etc/openvpn/easy-rsa source vars # Script isn't executable :-s chmod +x /etc/openvpn/easy-rsa/make-crl # Finally we create the revocation list /etc/openvpn/easy-rsa/make-crl /etc/openvpn/keys/certification_revocation_list.pem To revoke some certification: # First load (source) the needed config cd /etc/openvpn/easy-rsa source vars ./revoke-full client2 See http://openvpn.net/index.php/documentation/howto.html#revoke for more informations. Hardening the setuptls-authman-in-the-middle-attack, also know as eavesdropping. On server side, in the directory where we created the keys: cd /etc/openvpn_keys/examples/easy-rsa/keys openvpn --genkey --secret ta.key cp ta.key /etc/openvpn Edit now the server.conf and uncomment the line Now on client side, copy in a secure maner (scp) the Edit now the client.conf and uncomment the line Other cipherWith a default setup the Blowfish cipher is used. One server and client side, uncomment the line LoggingNo default logging is setup, in fact all things are logged to the screen and not to a logfile. On server side define the line: log-append /var/log/openvpn/openvpn.log Now create this directory on the server: mkdir /var/log/openvpn.log chown root:adm /var/log/openvpn After having changed the server config file and restarted openvpn, you will
discover that nothings is sent on screen anymore, so check the logs ;-) Some
easy trick can be You can now create a script for the log rotating. See the directory I created a file # logrotate for openvpn
/var/log/openvpn/openvpn.log {
rotate 999999
mail SomeUser@SomeMail.com
mailfirst
monthly
compress
delaycompress
missingok
notifempty
postrotate
/etc/init.d/openvpn restart > /dev/null
endscript
}The log file Startup script
On server side, i adjusted the file On client side, i won't let Tools
Things left to do
Config files
ResourcesBooks
On the web
Comments leaved by users (total: 0)
Add a comment[ Toggle on/off history ] Item History:
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||