How do I redirect only DNS traffic to use a tunnel interface when active?
Any other type of traffic should use the kernel's routing table instead. Whenever the tunnel interface is not active, DNS traffic is to use the kernel's routing table instead. Is this possible with iptables?
Note: I am using Strongswan 5.9.1, so if there is a way to configure this functionality from Strongswan, I would like to do that. However, I am using the system as a route based policy. Also, I am currently marking packets with strongswan, not sure if that would be related.
Interfaces:
# ip -br a
lo UNKNOWN 127.0.0.1/8 ::1/128
ens3 UP 192.168.0.15/24 fe80::e74:fcff:fe28:cb00/64
ens4 UP 2.2.1.2/30 fe80::e74:fcff:fe28:cb01/64
virbr0 DOWN 192.168.122.1/24
virbr0-nic DOWN
ip_vti0@NONE DOWN
vti01@NONE UNKNOWN 172.21.0.3/32 fe80::200:5efe:202:102/64
Routes:
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 ens3
2.2.0.1 0.0.0.0 255.255.255.255 UH 101 0 0 ens4
2.2.1.0 0.0.0.0 255.255.255.252 U 101 0 0 ens4
3.3.0.0 2.2.0.1 255.255.255.252 UG 101 0 0 ens4
3.3.1.0 2.2.1.1 255.255.255.252 UG 101 0 0 ens4
10.212.134.0 192.168.0.1 255.255.255.0 UG 100 0 0 ens3
172.21.0.0 0.0.0.0 255.255.255.248 U 0 0 0 vti01
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens3
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
I tried using the following rule:
# iptables -t mangle -A OUTPUT -p udp --dport 53 --out-interface vti01
I can see the rule, but when I watch it, no packets are going into the rule when I do a dig request on the same host.
# watch -n1 iptables -t mangle -nvL
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 udp -- * vti01 0.0.0.0/0 0.0.0.0/0 udp dpt:53
What am I missing?