This sounds similar to kill-switch behavior and searching that might come up with other solutions.
Actually I thought about to implement a kill-switch as a solution.
On librewolf I have something of similar behaviour.
A proxy extension called Mullvad Proxy.
If I am not wrong it acts as a kill-switch if the wg-interface lose connection to the VPN server.
I tried it out, while being connected to the proxy, and turning of the wg-interface.
The browser responded with a time-out while trying to connect to a web page.
I'd feel more confident in having an OS firewall limit communications over all network interfaces except a specific one.
As a firewall I am using an IPFW2 one.
It is actually the "workstation" profile FreeBSD provides.
Code:
Input:
# ipfw list
Output:
00100 allow ip from any to any via lo0
00200 deny ip from any to 127.0.0.0/8
00300 deny ip from 127.0.0.0/8 to any
00400 deny ip from any to ::1
00500 deny ip from ::1 to any
00600 allow ipv6-icmp from :: to ff02::/16
00700 allow ipv6-icmp from fe80::/10 to fe80::/10
00800 allow ipv6-icmp from fe80::/10 to ff02::/16
00900 allow ipv6-icmp from any to any icmp6types 1
01000 allow ipv6-icmp from any to any icmp6types 2,135,136
01100 check-state :default
01200 allow tcp from me to any established
01300 allow tcp from me to any setup keep-state :default
01400 allow udp from me to any keep-state :default
01500 allow icmp from me to any keep-state :default
01600 allow ipv6-icmp from me to any keep-state :default
01700 allow udp from 0.0.0.0 68 to 255.255.255.255 67 out
01800 allow udp from any 67 to me 68 in
01900 allow udp from any 67 to 255.255.255.255 68 in
02000 allow udp from fe80::/10 to me 546 in
02100 allow icmp from any to any icmptypes 8
02200 allow ipv6-icmp from any to any icmp6types 128,129
02300 allow icmp from any to any icmptypes 3,4,11
02400 allow ipv6-icmp from any to any icmp6types 3
65000 count ip from any to any
65100 deny { tcp or udp } from any to any 135-139,445 in
65200 deny { tcp or udp } from any to any 1026,1027 in
65300 deny { tcp or udp } from any to any 1433,1434 in
65400 deny ip from any to 255.255.255.255
65500 deny ip from any to 224.0.0.0/24 in
65500 deny udp from any to any 520 in
65500 deny tcp from any 80,443 to any 1024-65535 in
65500 deny log logamount 500 ip from any to any
65535 deny ip from any to any
My interface through which all traffic usually goes is:
Code:
Input:
ifconfig | grep wg
Output:
xy-xyz-wg-NNN
Looking at the firewall rules they seem ok, but I wonder how or where I could implement the kill-switch rule.
Let us assume that I have the following inet addresses available on my wg-interface:
-> inet v4: 13.88.01.120
-> inet v6: ac00:abcd:bcad:ab30:ac01::1:3add prefixlen 130
I basically have in mind to do something like that:
Code:
---- I do not thing I should change that part
00100 allow ip from any to any via lo0
00200 deny ip from any to 127.0.0.0/8
00300 deny ip from 127.0.0.0/8 to any
00400 deny ip from any to ::1
00500 deny ip from ::1 to any
--- END of the part I should not change
--- I thought about to start to edit from here.
00550 deny ip from any to any via ue0 (To get the actual kill-switch behaviour either here or at the end)
--- And add a via wg interface add the end of almost each line starting from here if still needed.
00600 allow ipv6-icmp from :: to ff02::/16 via my-wg-interface
00700 allow ipv6-icmp from fe80::/10 to fe80::/10 via ...
00800 allow ipv6-icmp from fe80::/10 to ff02::/16 via ...
00900 allow ipv6-icmp from any to any icmp6types 1 via ...
01000 allow ipv6-icmp from any to any icmp6types 2,135,136
01100 check-state :default
01200 allow tcp from me to any established via ...
01300 allow tcp from me to any setup keep-state :default via ...
01400 allow udp from me to any keep-state :default via ...
01500 allow icmp from me to any keep-state :default via ...
01600 allow ipv6-icmp from me to any keep-state :default via ...
01700 allow udp from 0.0.0.0 68 to 255.255.255.255 67 out via ...
01800 allow udp from any 67 to me 68 in via ...
01900 allow udp from any 67 to 255.255.255.255 68 in via ...
02000 allow udp from fe80::/10 to me 546 in via...
02100 allow icmp from any to any icmptypes 8 via ...
02200 allow ipv6-icmp from any to any icmp6types 128,129 via ...
02300 allow icmp from any to any icmptypes 3,4,11 via ...
02400 allow ipv6-icmp from any to any icmp6types 3 via...
--- END of editing
65000 count ip from any to any
65100 deny { tcp or udp } from any to any 135-139,445 in
65200 deny { tcp or udp } from any to any 1026,1027 in
65300 deny { tcp or udp } from any to any 1433,1434 in
65400 deny ip from any to 255.255.255.255
65500 deny ip from any to 224.0.0.0/24 in
65500 deny udp from any to any 520 in
65500 deny tcp from any 80,443 to any 1024-65535 in
65500 deny log logamount 500 ip from any to any
65535 deny ip from any to any via ue0 (To get the actual kill-switch behaviour)
Now the problem would be, my interface name changes all the time, because I am connecting to a new interface each day.
Eventually modyfing just rule number 65535 to deny any in and outgoing connections through ue0 would be the solution here, or deny any in and outgoing connections through ue0 at the beginning.
As I understand deny ip from any to any includes ipv4 and ipv6 addresses, right ?
Another solution would be to add something like that to the wg-config files implementing a kill-switch behaviour per file.
Code:
PostUp = iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT && ip6tables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
PreDown = iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT && ip6tables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
Firewall Builder in this case does not work as intended.
Someone said on the internet that there are pf iptables for FreeBSD ?
I have not found anything, though.
I looked up the man-page from rtorrent.
It can do something simple as
rtorrent bind -b 13.88.01.120 my-torrent-file
I agree with you though, a kill-switch behavior would be the all-in-one solution.
Or even better just disallow all in and outgoing connections throug ue, and only allow them through wg.
That would be a global kill-switch I guess since nothing would work anymore through ue0.