I want to block some devices (IP Cameras) from the Internet to prevent them from phoning home to the cloud. I have configured static IP lease so their IP address is fixed.
This is the rule I have in /etc/config/firewall:
config rule
option name 'Block-Cameras'
option src 'lan'
option target 'REJECT'
list proto 'tcp'
list proto 'udp'
option dest 'wan'
list src_ip '192.168.0.21'
nft list ruleset shows the rule was installed into nftables:
chain forward_lan {
meta l4proto tcp ip saddr 192.168.0.21 counter packets 3 bytes 156 jump reject_to_wan comment "!fw4: Block-Cameras"
meta l4proto udp ip saddr 192.168.0.21 counter packets 26660 bytes 2527440 jump reject_to_wan comment "!fw4: Block-Cameras"
jump accept_to_wan comment "!fw4: Accept lan to wan forwarding"
jump accept_to_lan
}
However, I am still seeing the video feed from the cloud app and tcpdump shows the packets are passing through:
root@FriendlyWrt:~# tcpdump -i br-lan host 192.168.0.21 -s0 -nn
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on br-lan, link-type EN10MB (Ethernet), snapshot length 262144 bytes
12:30:48.783827 IP 192.168.0.21.35421 > 50.19.254.134.10240: UDP, length 40
12:30:48.784202 IP 192.168.0.1 > 192.168.0.21: ICMP 50.19.254.134 udp port 10240 unreachable, length 76
12:30:48.783828 IP 192.168.0.21.35421 > 122.248.234.207.10240: UDP, length 40
12:30:48.784350 IP 192.168.0.1 > 192.168.0.21: ICMP 122.248.234.207 udp port 10240 unreachable, length 76
12:30:48.783850 IP 192.168.0.21.35421 > 122.226.84.253.10240: UDP, length 40
12:30:48.784466 IP 192.168.0.1 > 192.168.0.21: ICMP 122.226.84.253 udp port 10240 unreachable, length 76
...
12:30:48.784064 IP 192.168.0.21.35421 > 129.80.110.57.10001: UDP, length 288
12:30:48.784134 IP 192.168.0.21.35421 > 192.168.1.1.10000: UDP, length 288
12:30:48.784174 IP 192.168.0.21.35421 > 141.147.50.196.10001: UDP, length 288
12:30:48.784296 IP 192.168.0.21.35421 > 89.168.126.249.10001: UDP, length 288
...
12:30:48.947299 IP 141.147.50.196.10001 > 192.168.0.21.35421: UDP, length 288
12:30:48.947956 IP 89.168.126.249.10001 > 192.168.0.21.35421: UDP, length 288
12:30:49.007743 IP 129.80.110.57.10001 > 192.168.0.21.35421: UDP, length 288
Edit: Apparently some packets are blocked (rejected) but the ones to the cloud service aren't. I installed a tracing rule in nftables and here is the monitor trace:
trace id 4e9c0651 ip trace_table trace_chain packet: iif "br-lan" ether saddr 00:62:6e:65:3c:72 ether daddr b2:42:33:1e:
ab:bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 64 ip id 10529 ip length 76 udp sp
ort 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 4e9c0651 ip trace_table trace_chain rule ip saddr 192.168.0.21 meta nftrace set 1 (verdict continue)
trace id 4e9c0651 ip trace_table trace_chain verdict continue
trace id 4e9c0651 ip trace_table trace_chain policy accept
trace id 4e9c0651 inet fw4 raw_prerouting packet: iif "br-lan" ether saddr 00:62:6e:65:3c:72 ether daddr b2:42:33:1e:ab:
bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 64 ip id 10529 ip protocol udp ip len
gth 76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 4e9c0651 inet fw4 raw_prerouting verdict continue
trace id 4e9c0651 inet fw4 raw_prerouting policy accept
trace id 4e9c0651 inet fw4 mangle_prerouting packet: iif "br-lan" ether saddr 00:62:6e:65:3c:72 ether daddr b2:42:33:1e:
ab:bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 64 ip id 10529 ip protocol udp ip
length 76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 4e9c0651 inet fw4 mangle_prerouting verdict continue
trace id 4e9c0651 inet fw4 mangle_prerouting policy accept
trace id 4e9c0651 inet fw4 prerouting packet: iif "br-lan" ether saddr 00:62:6e:65:3c:72 ether daddr b2:42:33:1e:ab:bf i
p saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 64 ip id 10529 ip protocol udp ip length
76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 4e9c0651 inet fw4 prerouting rule iifname "br-lan" jump helper_lan comment "!fw4: Handle lan IPv4/IPv6 helper a
ssignment" (verdict jump helper_lan)
trace id 4e9c0651 inet fw4 helper_lan verdict continue
trace id 4e9c0651 inet fw4 prerouting verdict continue
trace id 4e9c0651 inet fw4 prerouting policy accept
trace id 4e9c0651 inet nft-qos-monitor download packet: iif "br-lan" ether saddr 00:62:6e:65:3c:72 ether daddr b2:42:33:
1e:ab:bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 64 ip id 10529 ip protocol udp
ip length 76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 4e9c0651 inet nft-qos-monitor download verdict continue
trace id 4e9c0651 inet nft-qos-monitor download policy accept
trace id 7204081a inet fw4 mangle_forward packet: iif "br-lan" oif "eth0" ether saddr 00:62:6e:65:3c:72 ether daddr b2:4
2:33:1e:ab:bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 63 ip id 10529 ip protocol
udp ip length 76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 7204081a inet fw4 mangle_forward verdict continue
trace id 7204081a inet fw4 mangle_forward policy accept
trace id 7204081a inet fw4 forward packet: iif "br-lan" oif "eth0" ether saddr 00:62:6e:65:3c:72 ether daddr b2:42:33:1e
:ab:bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 63 ip id 10529 ip protocol udp ip
length 76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 7204081a inet fw4 forward rule ct state vmap { established : accept, related : accept } comment "!fw4: Handle f
orwarded flows" (verdict accept)
trace id 7204081a inet fw4 mangle_postrouting packet: iif "br-lan" oif "eth0" ether saddr 00:62:6e:65:3c:72 ether daddr
b2:42:33:1e:ab:bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 63 ip id 10529 ip prot
ocol udp ip length 76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 7204081a inet fw4 mangle_postrouting verdict continue
trace id 7204081a inet fw4 mangle_postrouting policy accept
trace id 7204081a inet nft-qos-monitor upload packet: iif "br-lan" oif "eth0" ether saddr 00:62:6e:65:3c:72 ether daddr
b2:42:33:1e:ab:bf ip saddr 192.168.0.21 ip daddr 141.147.50.196 ip dscp cs0 ip ecn not-ect ip ttl 63 ip id 10529 ip prot
ocol udp ip length 76 udp sport 35421 udp dport 10001 udp length 56 udp checksum 32896
trace id 7204081a inet nft-qos-monitor upload rule ip saddr 192.168.0.21 counter packets 349076 bytes 397114265 (verdict
continue)
trace id 7204081a inet nft-qos-monitor upload verdict continue
trace id 7204081a inet nft-qos-monitor upload policy accept
Edit: It seems that the old connections (to 141.147..., 89.168..., 129.80..) are established in the NAT so it is not filtered? I read the solution is to flush the conntrack but I can't do echo f > /proc/net/nf_conntrack because the file has only read permissions. conntrack -F also does not work as I do not have the file or package.
I thought switching to OpenWRT would make things easier. But I have no idea what such a simple task seems impossible to do.