How to redirect all traffic *only* through tun?

Need help configuring your VPN? Just post here and you'll get that help.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Post Reply
0xlee
OpenVpn Newbie
Posts: 1
Joined: Fri Jul 23, 2021 8:26 pm

How to redirect all traffic *only* through tun?

Post by 0xlee » Fri Jul 23, 2021 8:44 pm

I have a centos7 server as openvpn server. with config:
[oconf=]
port 1194
proto tcp
dev tun
user nobody
group nobody
persist-key
persist-tun
keepalive 10 120
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
#push "redirect-gateway def1 bypass-dhcp"
#push "dhcp-option DNS 8.8.8.8"
#push "dhcp-option DNS 8.8.4.4"
dh none
ecdh-curve prime256v1
tls-crypt tls-crypt.key
crl-verify crl.pem
ca ca.crt
cert server_eRfOJALiZ3H9kDRc.crt
key server_eRfOJALiZ3H9kDRc.key
auth SHA256
cipher AES-128-GCM
ncp-ciphers AES-128-GCM
tls-server
tls-version-min 1.2
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
client-config-dir /etc/openvpn/ccd
status /var/log/openvpn/status.log
log /var/log/openvpn.log
log-append /var/log/append-openvpn.log
verb 3
[/oconf]

a openvpn client in freebsd server with config:
[oconf=]
client
proto tcp
remote *.*.*.* 1194
dev tun
resolv-retry infinite
persist-key
persist-tun

nobind
route-noexec
remote-cert-tls server
verify-x509-name server_eRfOJALiZ3H9kDRc name
auth SHA256
auth-nocache
cipher AES-128-GCM
tls-client
tls-version-min 1.2

tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
ignore-unknown-option block-outside-dns
setenv opt block-outside-dns # Prevent Windows 10 DNS leak
verb 3
[/oconf]

I already set: iptables -t nat -I POSTROUTING -o eth0 -s 10.8.0.0/24 -j MASQUERADE in my server side.However if I turn on redirect-gateway option. I find all my traffic will go through the openvpn-server. I only want my traffic go through it when I ask. for example
I want to redirect traffic when I put comand like: 「curl --interface utun15001 www.google.com」. If I turn off the redirect-gateway option, I can only get result from 「curl --interface utun15001 10.8.0.1」,get curl: (7) Couldn't connect to server when I put 「curl --interface utun15001 www.google.com」.

So how to redirect all traffic only through tun? Need help!

TinCanTech
OpenVPN Protagonist
Posts: 11137
Joined: Fri Jun 03, 2016 1:17 pm

Re: How to redirect all traffic *only* through tun?

Post by TinCanTech » Fri Jul 23, 2021 10:56 pm

You can not ...

Post Reply