LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   VPN - OpenVPN/PPTP (https://www.linuxquestions.org/questions/linux-server-73/vpn-openvpn-pptp-701848/)

ElLunchbox 02-03-2009 03:26 AM

VPN - OpenVPN/PPTP
 
Hi,

I currently have a server that sits behind a router at home (router IP 192.168.1.254, server IP 192.168.1.100). I would like to setup a VPN to a) access files hosted on the server b) have as a secure gateway when using unsecured wireless. I realise that this can be acomplished by 2 types of VPN, but if possible would like a bit of guidance about which is which and how to configure them (i.e. setting up the routing/IPs of the network). Thanks in advance.

watcher69b 02-03-2009 09:54 AM

a. i think your best bet would be openvpn. there is an extensive how to on their website that will tell you step by step how to configure it as well as how to make the files you want accessable. You will also find that there is lots of support for the oVPN software.

b. I think I know what your saying. You want to be able to use your vpn sever to browse the internet while on a non-secure wireless?

ElLunchbox 02-04-2009 02:22 AM

Quote:

Originally Posted by watcher69b (Post 3430448)
b. I think I know what your saying. You want to be able to use your vpn sever to browse the internet while on a non-secure wireless?

Thanks for the reply. Yer essentially I want to be able to VPN into my server at home from my laptop (for instance if I were on the unsecured wireless on the train), so that the internet is tunneled through the server at home and is therefore as secure as the home network. Can this be achieved via openvpn, or would it be worth setting up a different VPN for this? Basically, there are 2 instances that I would use VPN for a) accessing samba shared files but still browsing through loactions connection (e.g. @friends house) so you're suggesting openvpn, and b) securing unsecured wireless for using internet banking when on the train etc...

Thanks in advance.

watcher69b 02-05-2009 05:53 AM

OpenVPN sounds like your best bet. you can have a simple connection like that up and running in about an hour.

if you google openvpn and click on the howto link it will walk you through the whole process. it looks daunting but its really not. just make sure you read the steps in their entirety before you do anything.

As a tip:
The only problem i had with it was allowing my openvpn IP range access to the lan 192.168.1.x
Because the 10.8.0.x they tell you to use didnt mesh with out route statements. I ended up having my vpn 192.168.2.x and telling my router that it was on a class b (192.168.x.x) now it works perfectly.

Also if you dont have a static IP such as with Comcast/Metrocast sign up for a dydns account. They are free and it will allow you to connect even if your IP changes...
www.dyndns.com

to help you on your way here is my client config.
I will post my server config later...
#######################################################
client
dev tun
proto UDP # you can also choose TCP if you want to...
remote myddnshostname.com 1194
resolv-retry infinite
nobind
# Downgrade privileges after initialization (non-Windows only)
user nobody
group nobody
# Try to preserve some state across restarts.
persist-key
persist-tun
# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings
ca /home/.../vpn/cert-authority-name.crt
cert /home/.../vpn/laptopname.crt
key /home/.../vpn/laptopname.key
ns-cert-type server
tls-auth /home/.../vpn/ta.key 1
cipher CIPHERNAME
comp-lzo
# Set log file verbosity.
verb 3
# Silence repeating messages
mute 5
#######################################################

watcher69b 02-05-2009 06:55 AM

Server config

# Which local IP address should OpenVPN
# listen on? (optional)
local 192.168.2.1

# Which TCP/UDP port should OpenVPN listen on?
# You will need to
# open up this port on your firewall.
port 1194

# TCP or UDP server?
proto udp

# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
;dev tap
dev tun


# SSL/TLS root certificate (ca), certificate

ca /etc/openvpn/.../CA-NAME.crt
cert /etc/openvpn/.../SERVERNAME.crt
key /etc/openvpn/.../SERVERNAME.key

# Diffie hellman parameters.
dh /etc/openvpn/.../dh1024.pem

# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 192.168.2.0 255.255.255.0

# Maintain a record of client <-> virtual IP address
# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt


;server-bridge

# Push routes to the client to allow it
# to reach other private subnets behind
# the server. Remember that these
# private subnets will also need
# to know to route the OpenVPN client
# address pool (10.8.0.0/255.255.255.0)
# back to the OpenVPN server.
push "route 192.168.0.0 255.255.0.0"


# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).

# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
# iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the VPN. This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.

# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
# ifconfig-push 10.9.0.1 10.9.0.2

# Suppose that you want to enable different
# firewall access policies for different groups
# of clients. There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
# group, and firewall the TUN/TAP interface
# for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
# modify the firewall in response to access
# from different clients. See man
# page for more info on learn-address script.
;learn-address ./script

# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
push "redirect-gateway def1 bypass-dhcp"

# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses. CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
push "dhcp-option DNS 192.168.1.1"
push "dhcp-option DNS 192.168.2.1"
push "dhcp-option WINS 192.168.1.1"


# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
;client-to-client

# The keepalive directive causes ping-like
# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120

# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be '0'
# on the server and '1' on the clients.
tls-auth /etc/openvpn/.../ta.key 0

# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
cipher CIPHERNAME

# Enable compression on the VPN link.
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo

# The maximum number of concurrently connected
# clients we want to allow.
max-clients #

# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
user nobody
group nobody

# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun

# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status openvpn-status.log

# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it. Use one
# or the other (but not both).
;log openvpn.log
log-append openvpn.log

# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 4

# Silence repeating messages. At most 20
# sequential messages of the same message
# category will be output to the log.
mute 20

ElLunchbox 02-05-2009 08:36 AM

Thanks for posting your config files. Really appreciate it. I'll have a forray into it at the weekend and let you know how I get on.

I'd already had a small foray into openvpn (i.e. set up dyndns, opened ports on router, setup cerficates etc), but after a few hours/days of trying I couldn't get it to work so gave up. Hopefully this time I'll be more successful. I think that the routing was giving me the problems tho. My server has a static IP of 192.168.1.100, with the router at 192.168.1.254. Could you explain what you mean by

Quote:

I ended up having my vpn 192.168.2.x and telling my router that it was on a class b (192.168.x.x) now it works perfectly.
Do I need to change the servers IP, and where do I need to forward the ports to?

watcher69b 02-06-2009 05:39 AM

well the easy answer is that you dont want your VPN clients bumping into your LAN clients.

If your local LAN is 192.168.1.1-254 then you should make your VPN addresses like 192.168.2.x something different so that clients to not have the same IP address.

192.168.1.x is considered a class c address space, giving you only 254 total IP addresses.
192.168.x.x is a class b, giving you 65,536 IP addresses
wiki -> http://en.wikipedia.org/wiki/Classfu...k#Class_ranges


I went one step further and made my VPN 192.168.2.x so that i could have 254 VPN connections and my LAN is 192.168.1.x for 254 internal users.
This way there would be no way that there would ever be a conflict with the IP addresses because each connection have its own private network.

Problem is that the 192.168.1.x sub net wont know about the 192.168.2.x subnet with out a route statement because their subnet masks would both be 255.255.255.0 (or 192.168.1.0/24).

so what i did was change my router from the default 192.168.1.254 255.255.255.0 to be 192.168.1.254 255.255.0.0 so that it could see both 192.168.2.x and 192.168.1.x with out adding route statements...



sorry i cant explain it well. if you really want to know how the networking side works. you may want to grab a ccna or Network+ book from amazon.com

ElLunchbox 02-06-2009 06:26 AM

Quote:

Originally Posted by watcher69b (Post 3434004)
so what i did was change my router from the default 192.168.1.254 255.255.255.0 to be 192.168.1.254 255.255.0.0 so that it could see both 192.168.2.x and 192.168.1.x with out adding route statements...


This is the bit that I didn't do last time! I could connect to the VPN but then couldn't see anything on it, or do anything with it, so this will be why. Thanks for clearing that up. One last (n00bish) question... is there any reason that I couldn't use 192.168.4.x as a subnet? If i'm correct some routers (netgear i think) use 192.168.2.x as their default IP range so there could be conflict there... Thanks again for all your help.

watcher69b 02-07-2009 05:39 AM

Sure you can use 192.168.x...
(any numbers from 0-254)

I just picked 1 and 2 because they are sequential


All times are GMT -5. The time now is 09:41 AM.