Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Problem with VPN server on Debian.

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
Glorn
Posts: 3
Joined: 2016-12-20 11:39

Problem with VPN server on Debian.

#1 Post by Glorn »

Hello everyone.

I have created a VPN server on Debian using OpenVPN software. Everything seems to work fine, I have also created an openvpn configuration file, but when I'm connecting to the vpn server from windows 7 through openvpn gui, it connects, but I have no internet. Packet forwarding is enabled and I also configurated the IPtables. I'll paste my server.conf file here and also a screen of iptables, hope you can help me solve this issue and thank you in advance.

Server.conf:

Code: Select all

# bound to a DHCP client.
;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.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.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 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"

# 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

# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names.  This is recommended
# only for testing purposes.  For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
;duplicate-cn

# 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 ta.key 0 # This file is secret

# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
;cipher BF-CBC        # Blowfish (default)
;cipher AES-128-CBC   # AES
;cipher DES-EDE3-CBC  # Triple-DES

# 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 100

# 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 nogroup

# 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 3

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

Glorn
Posts: 3
Joined: 2016-12-20 11:39

Re: Problem with VPN server on Debian.

#2 Post by Glorn »

Anyone?

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: Problem with VPN server on Debian.

#3 Post by reinob »

Glorn wrote:Anyone?

Code: Select all

status openvpn-status.log
What does openvpn-status.log tell you?
Debugging the Windows client may be very hard (and you won't get help here),
so I'd start with the server log.

After all, it's there for a reason... :)

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: Problem with VPN server on Debian.

#4 Post by reinob »

Oh BTW, according to your iptables screenshot you did NOT setup the forwarding, which nicely explains why your client has no connectivity beyond the server.

I think you're gonna have to RTFM. The F is for fine. And the M is for "man openvpn", search for "Routing:".

In *my* case (the debian server working fine with linux, android, maemo and jolla clients), I have this in my /etc/rc.local:

Code: Select all

iptables -A FORWARD -i eth0 -o tun1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -s 10.7.0.0/24 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.7.0.0/24 -o eth0 -j MASQUERADE
Obviously, you'll need to put your tun adapter there (maybe it's not "tun1"), and the right subnet.

Glorn
Posts: 3
Joined: 2016-12-20 11:39

Re: Problem with VPN server on Debian.

#5 Post by Glorn »

Sorry for not responding, I have been quite busy lately.

Anyway, I spent whole day today trying to make this work and still no progress. First of all, this is my openvpn-status.log during connection:

Code: Select all

OpenVPN CLIENT LIST
Updated, Fri Dec 30 21:27:41 2016
Common Name, Real Address, Bytes Received, Bytes Sent, Connected Since
piotrek,192.168.186.1:55222,6323,4822,Fri Dec 30 21:27:39 2016
ROUTING TABLE
Virtual Address, Common Name, Real Address, Last Ref
10.8.0.6,PIOTREK,192.168.186.1:55222,fRI dEC 30 21:27:39 2016
GLOBAL STATS
Max bcast/mcast queue length,0
END
Second of all I noticed that during startup there is sth like " rc.local couldn't start" some compatibility issues it says. This is what I have in my rc.local file:

Code: Select all

mkdir -p /dev/net
mknod /dev/net/tun c 10 200
iptables -A FORWARD -i eth0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -s 10.8.0.0/24 -o eth- -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
service openvpn restart
exit 0

In my VM settings, under "Network Adapter" I have "NAT:Used to share the host's IP address", is this ok? I've been reading about NatHack and I begin to be really confused. I did read about routing and tried solutions used here: https://community.openvpn.net/openvpn/w ... AndRouting but still nothing.

PS. Initially, I used this guide to create this VPN connection https://www.digitalocean.com/community/ ... n-debian-8

gerards
Posts: 2
Joined: 2018-01-01 20:13

Re: Problem with VPN server on Debian.

#6 Post by gerards »

I tried the suggested statements as well, because i have the same problem (no traffic through my vpn goes in or out, windows client connect fine to debian openvpn server)

iptables -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -A FORWARD -i eth0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -s 10.89.0.0/24 -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.89.0.0/24 -o eth0 -j MASQUERADE

But how can i DEBUG if traffic comes through?
On an average cisco box one has debug commands, is there something similair on the debian box for me ?

Anybody who can help?

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: Problem with VPN server on Debian.

#7 Post by ralph.ronnquist »

I would guess you'll need

Code: Select all

# echo 1 >  /proc/sys/ipv4/ip_forward
I'm not sure what's the Debian-of-today method to make it keep this across boots; it used to be done by editing /etc/sysctl.conf , but you probably can search it up.

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1400
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 79 times
Been thanked: 175 times

Re: Problem with VPN server on Debian.

#8 Post by steve_v »

gerards wrote:But how can i DEBUG if traffic comes through?
Add the LOG directive to your rule, then look in syslog.

As for making things persistent, I'm pretty sure /etc/sysctl.conf (or a new file in /etc/sysctl.conf.d/) is still the preferred method for sysfs tunables.
If iptables-persistent is installed, you can set up your rules then do 'iptables-save > /etc/iptables/rules.v4'. Rules will then be applied at boot without need for a script.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

Bulkley
Posts: 6383
Joined: 2006-02-11 18:35
Has thanked: 2 times
Been thanked: 39 times

Re: Problem with VPN server on Debian.

#9 Post by Bulkley »

Don't forget that your router may have an active firewall.

Does your VPN not have help for this? These things can be somewhat unique to each VPN. The one I use has a Web site program that will make a downloadable configuration for OpenVPN. The also have their own client software based on OpenVPN. They have a forum with all sorts of tips and help. Just saying.

With regard to IPtables, remember that an open port is a security problem.

gerards
Posts: 2
Joined: 2018-01-01 20:13

Re: Problem with VPN server on Debian.

#10 Post by gerards »

Tnx, i didn't realize know i had to switch on the forwarding, so i changed the sysctl file for it wright a way.
Now i have to find how i can accept all traffic to and from the tunnel i gues because i've put in the old IP-table again so my vpn is not wide open for the world
Anybody any idea's on the correct statement's??,
so far i've got this, but iptables is blocking something

# Allow traffic on the TUN interface.
-A INPUT -i tun0 -j ACCEPT
-A FORWARD -i tun0 -j ACCEPT
-A OUTPUT -o tun0 -j ACCEPT

# Allow forwarding traffic only from the VPN.
-A FORWARD -i tun0 -o eth0 -s 10.89.0.0/24 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

Kind Regards

kopper
Posts: 137
Joined: 2016-09-30 14:30

Re: Problem with VPN server on Debian.

#11 Post by kopper »

gerards wrote:Anybody any idea's on the correct statement's??,
so far i've got this, but iptables is blocking somethings
Do you accept new connections to your VPN port in INPUT chain? That is of course, if you have set iptables -P INPUT something else than ACCEPT.

For example (change protocol and port if needed):

Code: Select all

iptables -I INPUT 1 -i eth0 -p udp --dport 1194 -m state --state NEW -j ACCEPT
Don't forget the POSTROUTING chain's masquerade.

Code: Select all

iptables -t nat -A POSTROUTING -s 10.89.0.0/24 -o eth0 -j MASQUERADE
gerards wrote:But how can i DEBUG if traffic comes through?
With iptables -L -v you should see which rules "get hit" in two leftmost columns. 0 means no traffic ever hits the rule. Same for policies, on the first line of each chain (XX packets, YY bytes).
Debian 10.2 Stable with i3
Secure your stuff: Securing Debian Manual
Don't break your stuff: Source List Management DontBreakDebian

Post Reply