I put an OpenVPN server on port 1194 on an OpenWrt 10.03 router:
echo "nameserver 8.8.8.8" > /etc/resolv.conf; opkg update; opkg install luci-app-openvpn openvpn openssl-util openssh-sftp-server ntpd
vim /etc/ssl/openssl.cnf # modify a few lines
[ CA_default ]
dir = /etc/openvpn
new_certs_dir = $dir/certs
certificate = $dir/ca.crt
private_key = $dir/ca.key
touch /etc/openvpn/index.txt; touch /etc/openvpn/serial; echo 01 > /etc/openvpn/serial
openssl req -nodes -new -x509 -keyout /etc/openvpn/ca.key -out /etc/openvpn/ca.crt -days 3650 # give a common name, like: vpnserver
openvpn --genkey --secret /etc/openvpn/ta.key
openssl req -nodes -new -keyout /etc/openvpn/server.key -out /etc/openvpn/server.csr # give a common name, like: vpnserver
mkdir -p /etc/openvpn/certs; mkdir -p /etc/openvpn/private
openssl ca -out /etc/openvpn/server.crt -in /etc/openvpn/server.csr
time openssl dhparam -out /etc/openvpn/dh1024.pem 1024 # it could take 10 minutes!
# generate certs for clients [X = client number]
openssl req -nodes -new -keyout /etc/openvpn/clientX.key -out /etc/openvpn/clientX.csr # give a common name! it will be the user name
openssl ca -out /etc/openvpn/clientX.crt -in /etc/openvpn/clientX.csr
# e.g.:
openssl req -nodes -new -keyout /etc/openvpn/client1.key -out /etc/openvpn/client1.csr # give a common name! it will be the user name
openssl ca -out /etc/openvpn/client1.crt -in /etc/openvpn/client1.csr
vim /etc/config/openvpn
config 'openvpn' 'openvpn_server'
option 'enable' '1'
option 'port' '1194'
option 'proto' 'udp'
option 'dev' 'tap'
option 'ca' '/etc/openvpn/ca.crt'
option 'cert' '/etc/openvpn/server.crt'
option 'key' '/etc/openvpn/server.key'
option 'tls_auth' '/etc/openvpn/ta.key 0' # server: 0
option 'dh' '/etc/openvpn/dh1024.pem'
option 'comp_lzo' '1'
option 'server' '10.20.30.0 255.255.255.0'
option 'keepalive' '10 120'
option 'persist_key' '1'
option 'persist_tun' '1'
option 'mute' '20'
option 'verb' '3'
option 'client_to_client' '1'
list 'push' 'dhcp-option DNS 10.20.30.1'
/etc/init.d/openvpn enable
/etc/init.d/openvpn start
ifconfig -a | less
ping 10.20.30.1
# here comes the firewall part
vim /etc/config/firewall # modify it
config 'include'
option 'path' '/etc/firewall.user'
config 'redirect'
option 'src' 'wan'
option 'proto' 'udp'
option 'src_dport' '1194'
option 'dest_port' '1194'
option '_name' 'OpenVPN'
vim /etc/firewall.user # modify it
iptables -t nat -A prerouting_rule -i $WAN -p udp --dport 1194 -j ACCEPT
iptables -A input_rule -i $WAN -p udp --dport 1194 -j ACCEPT
iptables -A forwarding_rule -i tap+ -o br-lan -j ACCEPT
iptables -A forwarding_rule -i br-lan -o tap+ -j ACCEPT
iptables -A input_rule -i tap+ -j ACCEPT
iptables -A output_rule -o tap -j ACCEPT
/etc/init.d/firewall restart
# tar the files that goes to the client1
mkdir -p /root/client1
cp /etc/openvpn/ca.crt /root/client1/; cp /etc/openvpn/client1.crt /root/client1/; cp /etc/openvpn/client1.key /root/client1/; cp /etc/openvpn/ta.key /root/client1/
cd /root/; tar -cf client1.tar client1
# configure the client
# extract the client1.tar's content to "~/.cert" on the clients pc
# if you're using e.g.: Fedora/SELinux, then
restorecon -Rv ~/.cert*
# then:
# ca.crt: the ca certificate
# client1.crt: the users certificate
# client1.key: the users private key
# ta.key: tls authentication [1]
What could I do (on the server side) to increase security regarding this OpenVPN server? Here are some of my ideas:
- I
sed 's/1194/50000/'the port number to a higher one to make it harder for port scanners to find - iptables? I should only allow IP ranges [on the input chain] that I will use in reality? +Only allow my laptop's MAC address
- If I don't use my router (e.g.: when I'm sleeping) I just turn it off.
Is there anything I'm missing? From the ps command I can see that OpenVPN is run by root, which is unsafe. What else should I do to increase security?