FreeBSD Server
This setup describes the server part of setting up OpenVPN using routing. Clients connecting to the network will be on their own subnet and can connect to each other as well as the internal network. All the necessary routing will be pushed when connecting. I tried setting up bridging instead but ran into problems on my Kubuntu client.
Install
[root@snoopy ~]#cd /usr/ports/security/openvpn
[root@snoopy /usr/ports/security/openvpn]#make install
[root@snoopy ~]#cp -fr /usr/local/share/doc/openvpn/easy-rsa/2.0 /usr/local/etc/openvpn
[root@snoopy ~]#cd /usr/local/etc/openvpn
Configuration
export KEY_SIZE=2048
export KEY_COUNTRY="US"
export KEY_PROVINCE="CA"
export KEY_CITY="SanFrancisco"
export KEY_ORG="Schmut"
export KEY_EMAIL="mario@schmut.com"
# source the vars
[root@snoopy /usr/local/etc/openvpn]#. vars
# setup key directory
[root@snoopy /usr/local/etc/openvpn]#./clean-all
# setup cert authority
[root@snoopy /usr/local/etc/openvpn]#./build-ca
# create the server key. Accept the defaults and say Y twice
[root@snoopy /usr/local/etc/openvpn]#./build-key-server server
# i want to use tls-auth so this generates the key
[root@snoopy /usr/local/etc/openvpn]#openvpn --genkey --secret keys/ta.key
# this took about 45 minutes on my p3-733
[root@snoopy /usr/local/etc/openvpn]#openssl dhparam -out keys/dh2048.pem 2048
openvpn_enable="YES"
openvpn_if="tun" # for routing
[root@snoopy /usr/local/etc/openvpn]#ln keys/crl.pem .
port 1194
proto udp
dev tun0
ca keys/ca.crt
cert keys/server.crt
key keys/server.key
dh keys/dh2048.pem
server 192.168.10.0 255.255.255.0
ifconfig-pool-persist ipp.txt
# tell all clients about my home subnet
push "route 192.168.1.0 255.255.255.0"
crl-verify crl.pem
client-config-dir ccd
client-to-client
keepalive 10 120
tls-auth keys/ta.key 0
cipher BF-CBC
comp-lzo
max-clients 10
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
verb 3
Clients
This is the server side part of creating a client for my laptop "perky".
[root@snoopy /usr/local/etc/openvpn]#./build-key perky
ifconfig-push 192.168.10.4 192.168.10.1This tells perky to assume ip address 192.168.10.4 which is a PPP tunnel to 192.168.10.1. In conjunction with the
push "route 192.168.1.0 255.255.255.0"from above that's all perky needs to connect to the internal home network.
DNS
push "dhcp-option DNS 192.168.1.200"
Revocation
[root@snoopy /usr/local/etc/openvpn]#./revoke-full perky
Firewall
# this goes into my incoming rule set
pass in quick proto udp from any port > 1023 to any port = 1194 keep state group 200
NAT
map ed0 192.168.10.0/24 -> 0/32 portmap tcp/udp 30001:40000For those of you scratching their heads now, normally when going to say google.com you wouldn't go there via 192.168.1.1 but rather directly. This means that 192.168.1.1 which is the internal address of my home gateway doesn't need to do address translation for anybody but computers on the internal 192.168.1 subnet. The above rule indeed says that address translation also be done for computers on the VPN subnet of 192.168.10.
map ed0 192.168.10.0/24 -> 0/32
Then i went on to setup the Linux client.