View Full Version : [SOLVED] 18.04.4 Server: OpenVPN client connects but no Internet connectivity
vellofrell
June 27th, 2020, 12:09 AM
I don't even understand what is going on here or how I caused this.
Client can connect through its .ovpn client config file and maintain a stable tunnel. However there is no connectivity to the Internet through the tunnel whatsoever.
Client attempts to shell access by terminal into the server inside the established OpenVPN tunnel: Operation timed out.
Pinging the server at 10.8.0.1: Request timeout
SSH terminal shell into the server from outside the VPN tunnel can be done fine. It can then successfully ping another client device at 10.8.0.2 with no trouble. It can also ping another client device at 10.8.0.3 successfully, but none of these clients have outside Internet access while routing through their VPN tunnels.
The server can successfully ping 8.8.8.8 with no issue. Same with pinging 208.67.222.222. So it has some manner to send out data. But routing back incoming data is where it all falls apart.
I don't even know where to begin as it feels like I've tried every possible fix I've seen on this subject. I'm not at such a level that I can spot conflicting routing settings at a glance.
Here are my router settings:
Router LAN IPv4 address: 192.168.1.1
Subnet Mask: 255.255.255.0
DHCP start address: 192.168.1.2
DHCP end address: 192.168.1.254
DNS Server 1: 208.67.222.222
DNS Server 2: 208.67.220.220
DHCP start address: 192.168.1.10
DHCP end address: 192.168.1.254
Here is the netplan:
/etc/netplan$ cat config.yaml
network:
version: 2
renderer: networkd
ethernets:
enp2s0:
dhcp4: no
dhcp6: no
addresses: [192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [208.67.222.222, 208.67.220.220]
IPtables settings: (where "xxxx" means very customized port number)
cat rules.v4
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i enp2s0 -p udp --dport xxxx -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i tun0 -s 10.8.0.0/24 -j ACCEPT
-A INPUT -i enp2s0 -p tcp --dport xxxx -m state --state NEW -m recent --set --name SSH
-A INPUT -i enp2s0 -p tcp --dport xxxx -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j DROP
-A INPUT -i enp2s0 -p tcp --dport xxxx -j ACCEPT
COMMIT
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -s 10.8.0.0/24 -j MASQUERADE
COMMIT
Any other settings I should copy over? I'm at a complete loss.
darkod
June 27th, 2020, 07:57 AM
1) Are the clients windows or linux?
2) Post the content of your server.conf on the openvpn server. Use CODE tags for easier reading of output.
3) On the server check if forwarding is enabled in /etc/sysctl.conf. Post here the output of:
cat /etc/sysctl.conf | grep forward
vellofrell
June 27th, 2020, 05:04 PM
Darko, pasted below. Thanks.
1) Are the clients windows or linux?
2) Post the content of your server.conf on the openvpn server. Use CODE tags for easier reading of output.
3) On the server check if forwarding is enabled in /etc/sysctl.conf. Post here the output of:
cat /etc/sysctl.conf | grep forward
1) Clients include one Linux Ubuntu 18 Desktop machine, one MAC OSX client, and one Android phone. No Windows machines for now.
2) server.conf file.
# Which local IP address should OpenVPN# listen on? (optional)
;local a.b.c.d
# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194
# TCP or UDP server?
# proto tcp
proto udp
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key). Each client
# and the server must have their own cert and
# key file. The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca ca.crt
cert server.crt
key server.key # This file should be kept secret
# Diffie hellman parameters.
# Generate your own with:
# openssl dhparam -out dh2048.pem 2048
dh dh.pem
# Network topology
# Should be subnet (addressing via IP)
# unless Windows clients v2.0.9 and lower have to
# be supported (then net30, i.e. a /30 per client)
# Defaults to net30 (not recommended)
topology subnet
# 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 10.8.0.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 /var/log/openvpn/ipp.txt
# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface. Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0. Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients. Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the OpenVPN server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses. You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# 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
key-direction 0
# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
# Note that v2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC
auth SHA256
# Enable compression on the VPN link and push the
# option to the client (v2.4+ only, for earlier
# versions see below)
;compress lz4-v2
;push "compress lz4-v2"
# For compression compatible with older clients use comp-lzo
# 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 /var/log/openvpn/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 /var/log/openvpn/openvpn.log
;log-append /var/log/openvpn/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
# Notify the client that when the server restarts so it
# can automatically reconnect.
;explicit-exit-notify 1
3)
cat /etc/sysctl.conf | grep forward# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
# Uncomment the next line to enable packet forwarding for IPv6
#net.ipv6.conf.all.forwarding=1
darkod
June 27th, 2020, 07:22 PM
OK, it looks good in general. For the server.conf I would suggest to clean it up. Instead of keeping this default format with so many comments and unused options, make a version only with the lines necessary for your setup and use that instead.
Also, from client side do not test connectivity with ping. Those iptables rules do not include ping allowed. So even if the vpn tunnel is OK your server iptables will block the ping.
ssh is allowed so try with ssh to confirm connectivity. For example from the Ubuntu client try something like ssh username@10.8.0.1
Next, on the ubuntu dekstop are you opening the vpn tunnel with sudo rights? If it is setup as automatic start with openvpn.service it should be OK. But if you do it manually only when needed, you need to do it with sudo otherwise it can't configure correct route through the vpn tunnel. With the vpn connected check the routes present on the ubuntu client with:
ip route show
Post the here.
SeijiSensei
June 27th, 2020, 07:40 PM
Log into the server from outside while the tunnel is up. Can you ping the address on the other end of the tunnel? It's probably something like 10.8.0.2. On the server please post the results of
ip addr
ip route
inside
tags.
It looks like you have a local network with a 192.168.1.0/24 subnet. If so, you'll need a routing statement on the server telling it to send packets for addresses in that range down the tunnel. Something like
sudo ip route add 192.168.1.0/24 via 10.8.0.2
If packets arrive for 192.168.1.0/24 addresses, and there is no route telling the server what to do with them, it will send them out its default gateway to the Internet and thus into the void.
vellofrell
June 27th, 2020, 10:19 PM
OK, it looks good in general. For the server.conf I would suggest to clean it up. Instead of keeping this default format with so many comments and unused options, make a version only with the lines necessary for your setup and use that instead.
Also, from client side do not test connectivity with ping. Those iptables rules do not include ping allowed. So even if the vpn tunnel is OK your server iptables will block the ping.
ssh is allowed so try with ssh to confirm connectivity. For example from the Ubuntu client try something like ssh username@10.8.0.1
Next, on the ubuntu dekstop are you opening the vpn tunnel with sudo rights? If it is setup as automatic start with openvpn.service it should be OK. But if you do it manually only when needed, you need to do it with sudo otherwise it can't configure correct route through the vpn tunnel. With the vpn connected check the routes present on the ubuntu client with:
ip route show
Post the here.
Client desktop box cannot SSH into the server with
ssh user@10.8.0.1, even sitting on the same LAN.
The Ubuntu desktop is rigged up to automatically log into the VPN upon boot, with its client.conf file in /etc/openvpn/ssh/.
ip route show0.0.0.0/1 via 10.8.0.1 dev tun0
default via 192.168.1.1 dev eno2 proto dhcp metric 100
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2
128.0.0.0/1 via 10.8.0.1 dev tun0
169.254.0.0/16 dev eno2 scope link metric 1000
192.168.1.0/24 dev eno2 proto kernel scope link src 192.168.1.5 metric 100
Mind you this VPN problem happened just as my user keyring got completely messed up, as described here (https://ubuntuforums.org/showthread.php?t=2446169) - if that could have any effect.
SeijiSensei - will review your recommendations soon and get back.
darkod
June 27th, 2020, 10:38 PM
Well, the client sets up default route over tun0 once the vpn is connected. That is expected.
One thing. I forgot to notice earlier you seem to have special xxxx port for ssh also in iptables. If you did change the ssh port on the server, then trying to login to it by ssh should be:
ssh -p xxxx user@10.8.0.1
Did you take this into account when testing ssh to the server?
vellofrell
June 27th, 2020, 10:52 PM
Well, the client sets up default route over tun0 once the vpn is connected. That is expected.
One thing. I forgot to notice earlier you seem to have special xxxx port for ssh also in iptables. If you did change the ssh port on the server, then trying to login to it by ssh should be:
ssh -p xxxx user@10.8.0.1
Did you take this into account when testing ssh to the server?
Yessir, always times out even directed to the non-standard port number. It's a command I've used numerous times before, but definitely not working for now.
vellofrell
June 27th, 2020, 11:03 PM
Log into the server from outside while the tunnel is up. Can you ping the address on the other end of the tunnel? It's probably something like 10.8.0.2. On the server please post the results of
ip addr
ip route
inside
tags.
It looks like you have a local network with a 192.168.1.0/24 subnet. If so, you'll need a routing statement on the server telling it to send packets for addresses in that range down the tunnel. Something like
sudo ip route add 192.168.1.0/24 via 10.8.0.2
If packets arrive for 192.168.1.0/24 addresses, and there is no route telling the server what to do with them, it will send them out its default gateway to the Internet and thus into the void.
Sensei -
I have just shelled into the server using the outside DNS. I raised the VPN on this laptop. From the terminal shell, it successfully pings this laptop while I'm off-site.
ping 10.8.0.4PING 10.8.0.4 (10.8.0.4) 56(84) bytes of data.
64 bytes from 10.8.0.4: icmp_seq=1 ttl=64 time=116 ms
64 bytes from 10.8.0.4: icmp_seq=2 ttl=64 time=244 ms
64 bytes from 10.8.0.4: icmp_seq=3 ttl=64 time=172 ms
64 bytes from 10.8.0.4: icmp_seq=4 ttl=64 time=139 ms
64 bytes from 10.8.0.4: icmp_seq=5 ttl=64 time=209 ms
64 bytes from 10.8.0.4: icmp_seq=6 ttl=64 time=247 ms
64 bytes from 10.8.0.4: icmp_seq=7 ttl=64 time=115 ms
64 bytes from 10.8.0.4: icmp_seq=8 ttl=64 time=124 ms
64 bytes from 10.8.0.4: icmp_seq=9 ttl=64 time=403 ms
ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 1c:1b:0d:ff:25:ae brd ff:ff:ff:ff:ff:ff
inet 192.168.1.3/24 brd 192.168.1.255 scope global enp2s0
valid_lft forever preferred_lft forever
inet6 2605:a601:ac97:f000:1e1b:dff:feff:25ae/64 scope global dynamic mngtmpaddr
valid_lft 3595sec preferred_lft 3595sec
inet6 fe80::1e1b:dff:feff:25ae/64 scope link
valid_lft forever preferred_lft forever
3: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 100
link/none
inet 10.8.0.1/24 brd 10.8.0.255 scope global tun0
valid_lft forever preferred_lft forever
inet6 fe80::7966:617b:7d08:ce5/64 scope link stable-privacy
valid_lft forever preferred_lft forever
ip routedefault via 192.168.1.1 dev enp2s0 onlink
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.1
192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.3
When entering this: sudo ip route add 192.168.1.0/24 via 10.8.0.2
I see this...
sudo ip route add 192.168.1.0/24 via 10.8.0.2[sudo] password for USER:
RTNETLINK answers: File exists
as a reminder, since this connectivity issue cropped up just as my user keyring became botched up, perhaps that is causing this...? I don't know enough to tell either way, but the timing is hard to get past.
darkod
June 27th, 2020, 11:35 PM
When trying ping to clients in openvpn, be careful. The IP assignment is little weird, haven't been able to understand it 100% myself too.
I think the first client gets 10.8.0.6 and then each client +4. The second would be 10.8.0.10, etc.
So pinging 10.8.0.4 might not tell you what you think it does.
To have better idea of client IPs you can have status log file (which doesn't look included in your server.conf). A line with something like:
status /etc/openvpn/openvpn_status.log
After you restart the openvpn service on the server, it will create that log file and inside you can see connected clients and their vpn IP (the public IP too). The ping to client should be using that vpn IP if I remember correctly.
SeijiSensei
June 28th, 2020, 01:05 PM
When entering this:
sudo ip route add 192.168.1.0/24 via 10.8.0.2
I see this...
RTNETLINK answers: File exists
The problem is you already have a route for 192.168.1.0/24 on the server:
192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.3
The server has no interfaces in 192.168.1.0/24, does it? Try this:
sudo ip route del 192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.3
sudo ip route add 192.168.1.0/24 via 10.8.0.4
And, please, no colors or font changes. Use the code tag for things that need monospacing; leave everything else at the defaults.
vellofrell
July 2nd, 2020, 09:36 PM
Nothing worked, or I'm too limited in my knowledge of under-the-hood Ubuntu and networking that I could not apply any suggestions. I've already began putting together a new server with mostly duplicate settings from the old machine copied over to the new. That is no piece of cake either because of an apparent missing networking/ethernet driver for a combo of latest gen Intel Comet Lake CPUs and/or a new Gigabyte motherboard.
I'm open to further suggestions on rectifying the old machine's networking just for my own knowledge, though.
darkod
July 2nd, 2020, 09:51 PM
Yeah, a lot of things have been thrown in here. It might scare a novice... :)
Lets go back to basic, and try to pass us short and direct information.
First is to understand from where to where you are connecting.
1) Where is your openvpn server? Cloud VM, VM on your home LAN, etc...
2) Where is the client that you use for testing? Home LAN, etc...
3) What is your home LAN subnet? 192.168.1.0/24?
That's enough to start.
vellofrell
July 16th, 2020, 06:51 PM
Hi Darko, and others. So to continue with this troubleshoot, I began transferring the server configs to a newly-built rig. I had been planning this for some time anyway. Darko, months ago you gave me tips on proper iptables settings, and I essentially copied in to my /etc/iptables/rules.v4 file the settings you provided.
What I have here is this:
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i enp4s0 -p udp --dport port customport# -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i tun0 -s 10.8.0.1/24 -j ACCEPT
-A INPUT -i enp4s0 -p tcp --dport customport# -m state --state NEW -m recent --set --name SSH
-A INPUT -i enp4s0 -p tcp --dport customport# -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j DROP
-A INPUT -i enp4s0 -p tcp --dport customport# -j ACCEPT
COMMIT
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -s 10.8.0.1/24 -j MASQUERADE
COMMIT
"customport" to denote my really atypical port numbers I use for OpenVPN and SSH.
It worked great until everything flew off the rails as I was beginning to upgrade the server hardware. Now with these iptables settings, the openvpn raises, but there is no SSH access or Internet connectivity. In order to get back Internet and SSH on the new server box, I have to loosen up the iptables to some settings I had which you advised months ago are largely pointless because they allow too much traffic to come in.
Advice and suggestions are appreciated.
darkod
July 16th, 2020, 08:17 PM
So let me see I understand it correctly.
1) SSH and OpenVPN connectivity to the server is working normally.
2) The connected clients don't have internet when routing traffic through the server.
In the above iptables rules you have a small typo. Where you use the openvpn subnet it should be 10.8.0.0/24. Not 10.8.0.1/24. Modify that and either restart the server or just reload iptables rules with:
sudo iptables-restore < /etc/iptables/rules.v4
Maybe this typo is in fact creating the problems for you. After you fix that try connecting a client and test again.
vellofrell
July 18th, 2020, 02:24 AM
So let me see I understand it correctly.
1) SSH and OpenVPN connectivity to the server is working normally.
2) The connected clients don't have internet when routing traffic through the server.
In the above iptables rules you have a small typo. Where you use the openvpn subnet it should be 10.8.0.0/24. Not 10.8.0.1/24. Modify that and either restart the server or just reload iptables rules with:
sudo iptables-restore < /etc/iptables/rules.v4
Maybe this typo is in fact creating the problems for you. After you fix that try connecting a client and test again.
Thanks for the tip. I was wondering about that too (10.8.0.0/24. Not 10.8.0.1/24). I corrected that typo and tried rebooting with these as /etc/iptables/rules.v4:
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i enp4s0 -p udp --dport customport# -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i tun0 -s 10.8.0.0/24 -j ACCEPT
-A INPUT -i enp4s0 -p tcp --dport customport# -m state --state NEW -m recent --set --name SSH
-A INPUT -i enp4s0 -p tcp --dport customport# -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j DROP
-A INPUT -i enp4s0 -p tcp --dport customport# -j ACCEPT
COMMIT
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -s 10.8.0.0/24 -j MASQUERADE
COMMIT
After doing this, unfortunately there was no Internet or SSH connectivity, however the VPN clients did successfully connect to the server.
Worth noting perhaps is that "systemctl status networking.service" results in this:
$ systemctl status networking.service
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-07-17 19:48:01 CDT; 10s ago
Docs: man:interfaces(5)
Process: 7694 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
Process: 7682 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle (code=exited, status=0/SUCCESS
Main PID: 7694 (code=exited, status=1/FAILURE)
Jul 17 19:48:01 server systemd[1]: Starting Raise network interfaces...
Jul 17 19:48:01 server ifup[7694]: Missing required variable: address
Jul 17 19:48:01 server ifup[7694]: Missing required configuration variables for interface enp4s0/inet.
Jul 17 19:48:01 server ifup[7694]: Failed to bring up enp4s0.
Jul 17 19:48:01 server systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Jul 17 19:48:01 server systemd[1]: networking.service: Failed with result 'exit-code'.
Jul 17 19:48:01 server systemd[1]: Failed to start Raise network interfaces.
Here's the current netplan:
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
addresses:
- 192.168.1.2/24
gateway4: 192.168.1.1
nameservers:
addresses: [208.67.222.222, 208.67.220.220]
This too:
fquery eth0
Unknown interface eth0
Still novice at running an linux back-end, so the source of my headaches may be completely apparent to some but go right over my head.
darkod
July 18th, 2020, 09:51 AM
Hold on. I didn't catch that.
If the interface on your server is named enp4s0 then you need to use that in each iptables rule that is for that interface. And that includes the POSTROUTING rule.
Regarding the netplan config, it doesn't look good if the networking service is giving you errors. In the netplan yaml file modify the enp4s0 addresses line to: addresses: [ 192.168.1.2/24 ]
Make the IP to be in the same line.
Do those two modifications to the POSTROUTING rule and the netplan yaml and reboot the server. Or course, I assume your info that the interface is named enp4s0 is correct. If in doubt use ifconfig to check it. Or better, check your network interfaces with:
sudo lshw -C network
Always make sure you use correct interface names. That is very important for networking / iptables.
vellofrell
July 18th, 2020, 10:03 PM
Hold on. I didn't catch that.
If the interface on your server is named enp4s0 then you need to use that in each iptables rule that is for that interface. And that includes the POSTROUTING rule.
Regarding the netplan config, it doesn't look good if the networking service is giving you errors. In the netplan yaml file modify the enp4s0 addresses line to: addresses: [ 192.168.1.2/24 ]
Make the IP to be in the same line.
Do those two modifications to the POSTROUTING rule and the netplan yaml and reboot the server. Or course, I assume your info that the interface is named enp4s0 is correct. If in doubt use ifconfig to check it. Or better, check your network interfaces with:
sudo lshw -C network
Always make sure you use correct interface names. That is very important for networking / iptables.
I'm sure we're getting closer. The server kept Internet connectivity, and the VPN clients would successfully connect. But there was no SSH/SFTP into the server.
Pasting these again as they were on today's testing:
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i enp4s0 -p udp --dport customport# -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -i tun0 -s 10.8.0.0/24 -j ACCEPT
-A INPUT -i enp4s0 -p tcp --dport customport# -m state --state NEW -m recent --set --name SSH
-A INPUT -i enp4s0 -p tcp --dport customport# -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j DROP
-A INPUT -i enp4s0 -p tcp --dport customport# -j ACCEPT
COMMIT
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o enp4s0 -s 10.8.0.0/24 -j MASQUERADE
COMMIT
/etc/netplan/config.yaml
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
addresses:
[192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [208.67.222.222, 208.67.220.220]
darkod
July 18th, 2020, 10:46 PM
When you say "there was no ssh/sftp into the server", from where? The clients?
I assume you have ssh into the server in general, otherwise you wouldn't be able to connect and check iptables etc.
If you are testing ssh from vpn client to the server, it is normal not to work. ssh into the server is only allowed on interface enp4s0 and when coming from vpn client you are coming in on tun0. iptables doesn't allow ssh on tun0.
If you want to test that, you can add temporary rule on the server in terminal:
sudo iptables -A INPUT -i tun0 -p tcp --dport <ssh_port> -j ACCEPT
After that test connecting from client. You can delete the temporary iptables rule by using the same command only use -D instead of the -A. That will delete it.
vellofrell
July 19th, 2020, 05:04 AM
When you say "there was no ssh/sftp into the server", from where? The clients?
I assume you have ssh into the server in general, otherwise you wouldn't be able to connect and check iptables etc.
If you are testing ssh from vpn client to the server, it is normal not to work. ssh into the server is only allowed on interface enp4s0 and when coming from vpn client you are coming in on tun0. iptables doesn't allow ssh on tun0.
If you want to test that, you can add temporary rule on the server in terminal:
sudo iptables -A INPUT -i tun0 -p tcp --dport <ssh_port> -j ACCEPT
After that test connecting from client. You can delete the temporary iptables rule by using the same command only use -D instead of the -A. That will delete it.
Thanks for that tip. Since I like to shell into the server from inside my VPN tunnel, I have added that line to the rules.v4 file and all seems well.
vellofrell
July 19th, 2020, 07:47 AM
Darko (or others), while I have your ear, curious if this netplan config looks alright (please be as nit-picky as you like, syntax and all):
network: version: 2
renderer: networkd
ethernets:
enp4s0:
addresses:
[192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [208.67.222.222, 208.67.220.220]
The new server still won't reliably raise network interfaces on startup without my being physically present to reboot with the ethernet unplugged from the back, only to plug in the ethernet cable after the startup sequence has completed. That's the only reliable way to get this rig to do its job. This all arises from some kind of kernel module or driver problem involving a recently-released motherboard and how well it works with Linux (to best of my understanding). I couldn't even get the damn thing online at all without making a "network bond" on new system installation of 18.04.04 Server. So I may have a bond0 or bond1 (can't remember which) going on here. Should that be included it the netplan? I'm dying to know if that would solve the boot-up complications on the new rig.
The Cog
July 19th, 2020, 09:25 AM
You need to put the version on a new, indented line like this:
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
addresses:
[192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [208.67.222.222, 208.67.220.220]
I'm not really familiar with netplan, and am not sure what that last list of addresses (the 208's) is. Not sure if its valid, or needed.
The rest look good to me, except that although what you have is valid, I would peraopnally prefer if the list of addresses was on the same line as the key, like addresses: [192.168.1.2/24]
darkod
July 19th, 2020, 10:41 AM
Those look like opendns public dns servers.
Make sure with netplan yaml that everything is indented as needed. And also careful when pasting because if pasting loses the order, we can't be sure whether you have a typo or it is because of bad pasting.
I suggested couple of posts back to put the main IP in one single line. But I got misunderstood it seems.
Here is my home server:
network: version: 2
renderer: networkd
ethernets:
eno1:
addresses: [ 192.168.1.5/24 ]
gateway4: 192.168.1.1
nameservers:
addresses: [ 8.8.8.8, 8.8.4.4 ]
I hope when posted it keeps the formatting as it should. :)
darkod
July 19th, 2020, 10:43 AM
Yeah, it kept the formatting all right.
Open the yaml with nano and try to follow the above example. For the spaces/indent I think I never used tab. Simply use 3x spacebar (standard space) and that is a good indent for netplan yaml.
The Cog
July 19th, 2020, 11:30 AM
Thanks for the post of yours, darkod.
Now I understands that last line of addresses - it's the nameserver addresses. So here's my suggested fixes:
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
addresses: [192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [208.67.222.222, 208.67.220.220]
vellofrell
July 22nd, 2020, 11:22 PM
Thanks guys, the netplan and the itpables are in proper order on the new server rig now.
Powered by vBulletin® Version 4.2.2 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.