tl;dr (after hours of debugging with @krisFR): At least under Debian 8, never use virtual interfaces (eth0:1) for OpenVPN, instead apply the new debian iproute2
methods (manual approach) described here: https://wiki.debian.org/NetworkConfiguration#iproute2_method . It will route the traffic just well.
I was trying to setup OpenVPN on a machine where all the client traffic should be sent over the tunnel, so this is part of my server config:
local x.x.x.243
port 443
proto udp
dev tun
server 172.31.1.0 255.255.255.0
push "redirect-gateway def1 bypass-dhcp"
And my client config:
pull
resolv-retry infinite
mute-replay-warnings
redirect-gateway def1
script-security 1
The client is able to connect to the VPN and it can ping the VPN host at 172.31.1.1
, however if I try to ping google.com by domain or IP, I get a Request timeout for icmp_seq 0
message...
What can be causing this? Side note, I've uninstalled any firewall and I'm currently setting IPTables to:
iptables -A INPUT -i eth0:1 -m state --state NEW -p udp --dport 443 -j ACCEPT
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -o eth0:1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0:1 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -s 172.31.1.0/24 -o eth0:1 -j MASQUERADE
iptables -A OUTPUT -o tun+ -j ACCEPT
Thank you.
So I tried to ping on the client 213.30.5.46
(one of Google's IPs) and it didn't work, however I got this results:
Listening on the outgoing VPN IP (eth0:1): tcpdump -i eth0 -t host x.x.x.243
IP [CLIENT_IP x..].51060 > vpn.exampledomain.com.https: UDP, length 113
IP [CLIENT_IP x..].51060 > vpn.exampledomain.com.https: UDP, length 145
IP vpn.exampledomain.com.https > [CLIENT_IP x..].51060: UDP, length 81
IP [CLIENT_IP x..].51060 > vpn.exampledomain.com.https: UDP, length 145
IP [CLIENT_IP x..].51060 > vpn.exampledomain.com.https: UDP, length 145
IP [CLIENT_IP x..].51060 > vpn.exampledomain.com.https: UDP, length 145
At the same time, listening on tun0, I got this: tcpdump -i tun0
23:40:39.864798 IP 172.31.1.10 > cache.google.com: ICMP echo request, id 17942, seq 0, length 64
23:40:40.925951 IP 172.31.1.10 > cache.google.com: ICMP echo request, id 17942, seq 256, length 64
23:40:41.886679 IP 172.31.1.10 > cache.google.com: ICMP echo request, id 17942, seq 512, length 64
23:40:42.906125 IP 172.31.1.10 > cache.google.com: ICMP echo request, id 17942, seq 768, length 64
Here is the output of iptables -L -n -v
:
Chain INPUT (policy ACCEPT 34772 packets, 2265K bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT udp -- eth0:1 * 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:443
13 1092 ACCEPT all -- tun+ * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1437 96985 ACCEPT all -- tun+ * 0.0.0.0/0 0.0.0.0/0
0 0 ACCEPT all -- tun+ eth0:1 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT all -- eth0:1 tun+ 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT 32574 packets, 7919K bytes)
pkts bytes target prot opt in out source destination
13 1092 ACCEPT all -- * tun+ 0.0.0.0/0 0.0.0.0/0
Note: /proc/sys/net/ipv4/ip_forward
is set to 1
.
Targeted tcpdump -i eth0:1 -t host 213.30.5.46
while pinging the destination:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0:1, link-type EN10MB (Ethernet), capture size 262144 bytes
IP 172.31.1.10 > cache.google.com: ICMP echo request, id 16920, seq 0, length 64
IP 172.31.1.10 > cache.google.com: ICMP echo request, id 16920, seq 256, length 64
IP 172.31.1.10 > cache.google.com: ICMP echo request, id 16920, seq 512, length 64
IP 172.31.1.10 > cache.google.com: ICMP echo request, id 16920, seq 768, length 64
Nothing shows on the client, ping eventually times out.
The IP address used by OpenVPN local x.x.x.243
is setup on \etc\network\interfaces
as eth0:1
right after eth0
as:
auto eth0:1
iface eth0:1 inet static
address x.x.x.243
gateway x.x.x.129
netmask 255.255.255.128
dns-nameservers x.x.x.4 x.x.x.104