That's right, I've forgotten to post configs.
Please excuse my not having server config as I'm not the server admin/owner.
Also, my question is rather about the routing part so far. I just want to know if using default gw from tun0 for LAN on another interface on the same machine as tun0 is supposed to work.
Or perhaps there might be some server-side security features preventing this from working. Or maybe gateway forwarding like this is not possible except using bridged configuration. I just want to get this clear to start with, and if the answer is "possible", then I'll be very thankful if you point to any flaws in my PF config.
But if you tell me you absolutely need server config for further diagnosis, I'll ask the server owner. It's just that I've given him enough trouble so far and would like to clear up some general questions first, if you please.
Here's my
/etc/pf.conf:
out_if = "re1"
vpn_if = "tun0"
wir_if = "re0"
set block-policy return
set skip on lo0
nat on $out_if from 192.168.24.0/24 to any -> ($out_if)
nat on $wir_if from 192.168.26.0/27 to any -> ($wir_if)
nat on $out_if from 172.16.55.0/24 to any -> ($out_if)
nat on $vpn_if from any to 172.16.55.0/24 -> ($vpn_if)
nat on $out_if from any to 192.168.26.0/27 -> ($out_if)
#rdr pass on $out_if proto { tcp,udp } from 192.168.26.0/27 to 0.0.0.0 -> 172.16.55.2
anchor openvpn
pass in quick on $wir_if from any to any
pass out quick on $wir_if from any to any
pass in quick on $out_if from any to any
pass out quick on $out_if from any to any
block in quick all
block out quick all
In here wired iface
re0 receives Internet from router. Wired iface
re1 is connected to LAN where I want to forward Internet connection from
tun0, just like normal default gw is successfully forwarded there with "normal" wired configuration.
And for "
anchor openvpn" I have this in a separate file to be loaded when
tun0 is up:
pass out quick on tun0 from any to any keep state
pass in quick on tun0 from any to any keep state
Now here's routing table w/no VPN connection:
Internet:
Destination Gateway Flags Netif Expire
default 192.168.24.1 UGS re0
127.0.0.1 link#3 UH lo0
192.168.24.0/24 link#1 U re0
192.168.24.103 link#1 UHS lo0
192.168.26.0/27 link#2 U re1
192.168.26.1 link#2 UHS lo0
Then here's the same when VPN is up:
Internet:
Destination Gateway Flags Netif Expire
default 172.16.55.1 UGS tun0
$my_server_net 192.168.24.1 UGS re0
127.0.0.1 link#3 UH lo0
172.16.55.0/24 172.16.55.2 UGS tun0
172.16.55.1 link#4 UH tun0
172.16.55.2 link#4 UHS lo0
192.168.24.0/24 link#1 U re0
192.168.24.103 link#1 UHS lo0
192.168.26.0/27 link#2 U re1
192.168.26.1 link#2 UHS lo0
Here "
$my_server_net 192.168.24.1" is the route through my wired gw to the VPN server's public IP.
Here is the client conf I'm using:
client
dev tun
proto udp
remote $myserver $myport
nobind
persist-tun
cipher AES-256-CBC
verb 2
mute 3
push-peer-info
ping 10
ping-restart 60
server-poll-timeout 3
reneg-sec 2592000
sndbuf 100000
rcvbuf 100000
remote-cert-tls server
comp-lzo no
auth-user-pass
<ca>
-----BEGIN CERTIFICATE-----
[here goes certificate]...
-----END CERTIFICATE-----
</ca>
key-direction 1
<tls-auth>
#
# 2048 bit OpenVPN static key
#
[here goes static key]..
-----END OpenVPN Static key V1-----
</tls-auth>
<cert>
-----BEGIN CERTIFICATE-----
[here goes certificate]
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN PRIVATE KEY-----
...[here goes private key]
-----END PRIVATE KEY-----
</key>
Of course, I've hidden the real server IP and port.
Per my NAT rules I expect to forward VPN network
172.16.55.0/24 to LAN
192.168.28.0/27. When
tun0 is up
172.16.55.1 replaces default gw on the VPN-connected machine.
With NAT translation in both ways between VPN net and target LAN I expect this default gw to be forwarded to LAN just the way normal gw is forwarded in case of wired connection. In which case a LAN machine needs no other routes but LAN + gw belonging to LAN. The rest of the routing and forwarding is done on the router machine.