You can try this IPSET technique to have the router automatically collate the dynamic list of IPs associated with the domain.
As a proof of concept, enter the following commands:
Code:
ipset create Gmail_smtp hash:ip
echo ipset=/smtp.gmail.com/Gmail_smtp >> /jffs/configs/dnsmasq.conf.add
service restart_dnsmasq
nslookup smtp.gmail.com
ipset list Gmail_smtp
IPSET 'Gmail_smtp' will now contain a 'current' list of IPs associated with domain 'smtp.gmail.com'
NOTE: This list of IPs will be lost @ Reboot unless it is appropriately saved/restored etc.
NOTE: Any LAN device references to 'smtp.gmail.com' will cause the IPSET to be updated. (Clearly you can also force the refresh by scheduling the 'nslookup' command say once a day although this is not normally required.)
With a few tweaks for my setup, this is working great! One question ... is there any benefit to saving and restoring the Gmail_smtp ipset list versus just rebuilding it upon rebooting the router with a simple script for that purpose?
Thank you @Martineau !
... is there any benefit to saving and restoring the Gmail_smtp ipset list versus just rebuilding it upon rebooting the router with a simple script for that purpose?
Assuming you reboot say once a week, then it probably means the IPSET isn't full of potentiallyobsolete IP addresses.
So if you didn't require the save/restore function, then whilst it is quite drastic, the houskeeping is comprehensive.
P.S. Google probably aren't retiring and creating new SMTP servers every day so the size of the IPSET would be fairly static anyway.
@Martineau: Thank you for the script. Being a total newbie with firewall rules I am wondering whether your script can also be used to block internet access for various other IoT devices (e.g. smart thermostats, switches, lights etc.)?
I am thinking how to configure my network for home automation devices. Since it is not that easy to set up VLANs with Merlin one option might be to use your script to isolate them from internet and keep the possibility to reach them via VPN. What is your comment on that ?
@Martineau: Thank you for the script. Being a total newbie with firewall rules I am wondering whether your script can also be used to block internet access for various other IoT devices (e.g. smart thermostats, switches, lights etc.)?
I am thinking how to configure my network for home automation devices. Since it is not that easy to set up VLANs with Merlin one option might be to use your script to isolate them from internet and keep the possibility to reach them via VPN. What is your comment on that ?
Yes, that works fine. It is exactly what I used for my LAN. I created multiple ranges ex: .100-.130 for IP cameras, .150-.180 for IoT (smart home, etc ) and assigned DHCP reservations to those devices I need blocked from internet. I can still access the blocked devices via VPN.
@Martineau I am wondering whether your script can also be used to block internet access for various other IoT devices (e.g. smart thermostats, switches, lights etc.)?
Since it is not that easy to set up VLANs with Merlin one option might be to use your script to isolate them from internet and keep the possibility to reach them via VPN. What is your comment on that ?
I have tinkered with VLANs and created several: 20,30,40,50 and 200
e.g.
Code:
./GS108E.sh status
IoT vlan30 ACTIVE devices (ARP only accurate within 60secs?)
===============================================================
10.88.30.18 XX:XX:XX:XX:XX:XX N/A (HP-Spectre-X360.martineau.lan)
Internet vlan40 ACTIVE devices (ARP only accurate within 60secs?)
=================================================================
10.88.40.15 XX:XX:XX:XX:XX:XX Samsung-TV (?)
==================================================================
VPN (vlan50) br1 ACTIVE devices (ARP only accurate within 60secs?)
==================================================================
10.88.101.16 XX:XX:XX:XX:XX:XX N/A (HP-DM1.martineau.lan)
and Netdata (if installed on the router from entware-ng) can subsequently show separate VLAN activity
e.g. The vlan40 (Internet only) wired TV was playing a Netflix TV show episode, but I attached a wired PC into a different downstream switch's vlan30 (IoT) port and started an .iso download.
NOTE: Previously I also had two Sky+ boxes attached to vlan40, but since I had Sky Q installed, the Sky Q box stubbornly fails to connect to the internet if it 'detects' a vlan!!??.
So for hard wired devices that don't talk to each other this works nicely, but for WiFi IoT devices it can get a little more challenging with opening pin-holes in the firewall etc.
NOTE: Due to changes in v382.xx/v384.xx I have now adopted the use of device-group chains 'Myxxxxxx' to keep the firewall easier to modify (aka debug!)
Code:
Chain MyIPCAMs (1 references)
num pkts bytes target prot opt in out source destination
1 3697 281K ACCEPT udp -- br0 eth0 0.0.0.0/0 0.0.0.0/0 udp dpt:123
2 6684 401K DROP all -- br0 !tun2+ 10.88.8.120 0.0.0.0/0
3 117 7020 DROP all -- br0 !tun2+ 10.88.8.121 0.0.0.0/0
4 0 0 DROP all -- br0 !tun2+ 10.88.8.122 0.0.0.0/0
5 8363 502K DROP all -- br0 !tun2+ 10.88.8.123 0.0.0.0/0
6 0 0 DROP all -- br0 !tun2+ 10.88.8.124 0.0.0.0/0
7 7524 451K DROP all -- br0 !tun2+ 10.88.8.125 0.0.0.0/0
Code:
Chain FORWARD (policy DROP 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 476K 145M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 82238 6638K MyIPCAMs all -- * * 0.0.0.0/0 0.0.0.0/0
3 55776 4988K MyVLANs all -- * * 0.0.0.0/0 0.0.0.0/0
4 300 14698 MyAlexa all -- * * 0.0.0.0/0 0.0.0.0/0 match-set Alexa src,dst
5 0 0 other2wan all -- !br0 eth0 0.0.0.0/0 0.0.0.0/0
6 7787 348K DROP all -- * * 0.0.0.0/0 0.0.0.0/0 state INVALID
7 97 10565 ACCEPT all -- br0 br0 0.0.0.0/0 0.0.0.0/0
8 30698 3019K NSFW all -- * * 0.0.0.0/0 0.0.0.0/0
9 0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate DNAT
10 30698 3019K OVPN all -- * * 0.0.0.0/0 0.0.0.0/0 state NEW
11 30698 3019K ACCEPT all -- br0 * 0.0.0.0/0 0.0.0.0/0
Unlike cameras which only need to legitimately access NTP servers and possibly their home firmware notification sites, I'm not 100% sure of ALL legitimate ports used by IoT devices (such as Alexa) that must not be blocked.
So I have just cloned IPCamsBlock.sh to AlexaBlock.sh and created the following chain:
in order to track which ports (based on Alexa internet ports disclosure) need to be open outbound from any of my listed Alexa devices.
e.g. UDP 4172 is used for Alexa 'calling'
I suggest you implement port tracking for your IoT devices before you impose a Total port block.
NOTE: Whilst it is useful for statistics reporting, rather than have discrete rules for each Alexa-capable device, I simply chose to drop them all into an IPSET which triggers the chain port-tracking.
P.S. Next time you probably won't be so keen to ask for my comments!
Well it depends! ...but as already posted by @pilot04 - YES.
I have tinkered with VLANs and created several: 20,30,40,50 and 200
e.g.
Code:
./GS108E.sh status
IoT vlan30 ACTIVE devices (ARP only accurate within 60secs?)
===============================================================
10.88.30.18 XX:XX:XX:XX:XX:XX N/A (HP-Spectre-X360.martineau.lan)
Internet vlan40 ACTIVE devices (ARP only accurate within 60secs?)
=================================================================
10.88.40.15 XX:XX:XX:XX:XX:XX Samsung-TV (?)
==================================================================
VPN (vlan50) br1 ACTIVE devices (ARP only accurate within 60secs?)
==================================================================
10.88.101.16 XX:XX:XX:XX:XX:XX N/A (HP-DM1.martineau.lan)
and Netdata (if installed on the router from entware-ng) can subsequently show separate VLAN activity
e.g. The vlan40 (Internet only) wired TV was playing a Netflix TV show episode, but I attached a wired PC into a different downstream switch's vlan30 (IoT) port and started an .iso download.
NOTE: Previously I also had two Sky+ boxes attached to vlan40, but since I had Sky Q installed, the Sky Q box stubbornly fails to connect to the internet if it 'detects' a vlan!!??.
So for hard wired devices that don't talk to each other this works nicely, but for WiFi IoT devices it can get a little more challenging with opening pin-holes in the firewall etc.
NOTE: Due to changes in v382.xx/v384.xx I have now adopted the use of device-group chains to keep the firewall easier to modify (aka debug!)
Code:
Chain MyIPCAMs (1 references)
num pkts bytes target prot opt in out source destination
1 3697 281K ACCEPT udp -- br0 eth0 0.0.0.0/0 0.0.0.0/0 udp dpt:123
2 6684 401K DROP all -- br0 !tun2+ 10.88.8.120 0.0.0.0/0
3 117 7020 DROP all -- br0 !tun2+ 10.88.8.121 0.0.0.0/0
4 0 0 DROP all -- br0 !tun2+ 10.88.8.122 0.0.0.0/0
5 8363 502K DROP all -- br0 !tun2+ 10.88.8.123 0.0.0.0/0
6 0 0 DROP all -- br0 !tun2+ 10.88.8.124 0.0.0.0/0
7 7524 451K DROP all -- br0 !tun2+ 10.88.8.125 0.0.0.0/0
Code:
Chain FORWARD (policy DROP 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 476K 145M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 82238 6638K MyIPCAMs all -- * * 0.0.0.0/0 0.0.0.0/0
3 55776 4988K MyVLANs all -- * * 0.0.0.0/0 0.0.0.0/0
4 300 14698 MyAlexa all -- * * 0.0.0.0/0 0.0.0.0/0 match-set Alexa src,dst
5 0 0 other2wan all -- !br0 eth0 0.0.0.0/0 0.0.0.0/0
6 7787 348K DROP all -- * * 0.0.0.0/0 0.0.0.0/0 state INVALID
7 97 10565 ACCEPT all -- br0 br0 0.0.0.0/0 0.0.0.0/0
8 30698 3019K NSFW all -- * * 0.0.0.0/0 0.0.0.0/0
9 0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate DNAT
10 30698 3019K OVPN all -- * * 0.0.0.0/0 0.0.0.0/0 state NEW
11 30698 3019K ACCEPT all -- br0 * 0.0.0.0/0 0.0.0.0/0
Unlike cameras which only need to legitimately access NTP servers and possibly their home firmware notification sites, I'm not 100% sure of ALL legitimate ports used by IoT devices (such as Alexa) that must not be blocked.
So I have just cloned IPCamsBlock.sh to AlexaBlock.sh and created the following chain:
in order to track which ports (based on Alexa internet ports disclosure) need to be open outbound from any of my listed Alexa devices.
e.g. UDP 4172 is used for Alexa 'calling'
I suggest you implement port tracking for your IoT devices before you impose a Total port block.
NOTE: Whilst it is useful for statistics reporting, rather than have discrete rules for each Alexa-capable device, I simply chose to drop them all into an IPSET which triggers the chain port-tracking.
P.S. Next time you probably won't be so keen to ask for my comments!
@Martineau - I've been a long time user of IPCamsBlock.sh and would be interested in your newest version. I have also recently picked up an Alexa device and would be interested in AlexBlock.sh too. Any chance you could PM a link? Thanks in Advance. Appreciate the use of your scripts! -HardCat
The only difference between IPCamsBlock.sh v1.03 and my current v1.05 version is the use of a separate chain and in v1.04 I added (pointless?) tracking of the use of the NTP 123 port.
The only difference between IPCamsBlock.sh v1.03 and my current v1.05 version is the use of a separate chain and in v1.04 I added (pointless?) tracking of the use of the NTP 123 port.
I'm sure you can use other tools to perform the blocking/tracking etc?
However, I have renamed the AlexaBlock.sh script to IoTBlocking.sh and made it generic.
VPN issues
So, I have read through the thread and I'm using @Martineau IPCamsBlock.sh script (thank you for that) to block my camera from the Internet. The block works fine but I'm having trouble accessing the camera over VPN. No one else has made any complaints so I must be doing something wrong. I hope someone here can point me in the right direction.
What I want to do is use the Eye4 app that comes with VStarCam on my phone. I am connecting though OpenVPN for Android to my Asus router but all I get is "Offline".
I know that the block works because previously I could connect to the camera with the Eye4 app from anywhere (this is the reason I want to block it in the first place).
Status from IPCamsBlock
Code:
/jffs/scripts$ ./IPCamsBlock.sh status
[97m
(IPCamsBlock.sh): 2320 v1.04 I/P Cameras Firewall blocking.... status
[91m[93m
num pkts bytes target prot opt in out source destination
4 7 532 ACCEPT udp -- br0 eth0 0.0.0.0/0 0.0.0.0/0 udp dpt:123
5 402 26280 DROP all -- br0 !tun2+ 192.168.2.100 0.0.0.0/0
[97m
(IPCamsBlock.sh): 2320 I/P Cameras Firewall blocking status request completed.
[0m
iptables -L | grep DROP
Code:
/jffs/scripts$ iptables -L | grep DROP
DROP icmp -- anywhere anywhere icmp echo-request
DROP all -- anywhere anywhere state INVALID
DROP all -- anywhere anywhere
Chain FORWARD (policy DROP)
DROP all -- anywhere anywhere MAC 68:FB:7E:41:82:0B
DROP all -- VSTARCAM anywhere
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere state INVALID
DROP all -- anywhere anywhere state INVALID
DROP tcp -- anywhere anywhere tcpflags: FIN,SYN,RST,ACK/SYN
DROP tcp -- anywhere anywhere tcpflags: FIN,SYN,RST,ACK/RST
DROP icmp -- anywhere anywhere icmp echo-request
LOG all -- anywhere anywhere state NEW LOG level warning tcp-sequence tcp-options ip-options prefix "DROP "
DROP all -- anywhere anywhere
I'm using @Martineau IPCamsBlock.sh script (thank you for that)
The block works fine but I'm having trouble accessing the camera over VPN.
What I want to do is use the Eye4 app that comes with VStarCam on my phone. I am connecting though OpenVPN for Android to my Asus router but all I get is "Offline".
I also cannot access the two IPCams via VPN and I know that I missed something, even though I have read the thread at least three times to find the bit I missed.
Using version 1.04 of your script.
Here is my iptables
Code:
Chain FORWARD (policy DROP 0 packets, 0 bytes)
4 0 0 DROP all -- eth0 * 0.0.0.0/0 192.168.2.50 state NEW
5 3225 203K DROP all -- br0 !tun2+ 192.168.2.50 0.0.0.0/0
6 0 0 DROP all -- eth0 * 0.0.0.0/0 192.168.2.51 state NEW
7 232 16181 DROP all -- br0 !tun2+ 192.168.2.51 0.0.0.0/0
Shouldn't tun2+ be ACCEPT?
PS: If you release the IoTBlock script at some point would be awesome.
I also cannot access the two IPCams via VPN and I know that I missed something, even though I have read the thread at least three times to find the bit I missed.
Using version 1.04 of your script.
"ANY outbound traffic from either 192.168.2.50 or 192.168.2.51 that isn't routed via a VPN Server tunnel is DROP'd'"
You could try
Code:
./IPCamsBlock.sh init logdrop
./IPCamsBlock.sh status
iptables -nvL FORWARD --line
and you should now be able to see why the outbound camera traffic is being DROP'd, and there should be no DROP messages containing 'OUT=tun2' from either 192.168.2.50 or 192.168.2.51.
"ANY outbound traffic from either 192.168.2.50 or 192.168.2.51 that isn't routed via a VPN Server tunnel is DROP'd'"
You could try
Code:
./IPCamsBlock.sh init logdrop
./IPCamsBlock.sh status
iptables -nvL FORWARD --line
and you should now be able to see why the outbound camera traffic is being DROP'd, and there should be no DROP messages containing 'OUT=tun2' from either 192.168.2.50 or 192.168.2.51.
Only DROP's I can see are 'DROP IN=br0 OUT=eth0'. Nothing about tun2.
In case it helps:
I switched off the internet and captured the connections in my android phone while I was connecting to the camera. One app was connected to 10.0.0.1 and the other app to 203.205.128.130.
I have two different cameras each with each one app.
Only DROP's I can see are 'DROP IN=br0 OUT=eth0'. Nothing about tun2.
In case it helps:
I switched off the internet and captured the connections in my android phone while I was connecting to the camera. One app was connected to 10.0.0.1 and the other app to 203.205.128.130.
I have two different cameras each with each one app.
Hello @Martineau
I have been playing around with vlans to "secure" my IP camera stuff on AC87U, however without success. But I now found your gem!
I understand the splitting up between camera->internet and inbound VPN-only. However, I'm having a trust issue with my camera's being on my plain LAN (eg. if camera injects stuff on my NAS for example). That's why I went for vlans in the first place but did not succeed.
So basically, what I would like to achieve, is that on top of your outbound&inbound WAN, but opened VPN access, I'd like to have a block on OUTBOUND camera-> LAN, yet allowed INBOUND LAN -> camera. The latter is already available, but the first not.
Do you think that would be a nice addition to your script?
I'm guessing it's something like
iptables -I FORWARD 2 -s 192.168.222.98 -o eth0 -j DROP
But when I add this manually to my router, he still let me ping out from the camera IP towards my LAN.
VLANs would be the ideal solution although you may need additional VLAN capable switches for preferred hard-wired IP/Cameras etc. NOT sure why your foray into VLANs failed?
So basically, what I would like to achieve, is that on top of your outbound&inbound WAN, but opened VPN access, I'd like to have a block on OUTBOUND camera-> LAN, yet allowed INBOUND LAN -> camera.
LAN-LAN device traffic doesn't use router firewall rules as they are processed by the switch.
However, you could put the IP cameras on a Guest SSID, and set up an admin pin-hole access port from a specified LAN device, but I did play with a script
So I added 101 on port 3 (which is LAN2) where my NVR is going to be deployed. I've plugged in a standard pc, with fixed IP 192.168.222.98.
What happened is this:
Port 5 changed to 5Tagged which is odd, and not requested/intented. And even worse: my LAN & wifi devices cannot connect to vlan 101 or vice versa, but my vlan 101 can connect to the internet (which was not the objective at all, it should be revered). (eg ping from 192.168.222.100 to .98 fails, but from 98 to .1 and .100 succeeds)
So I'm not sure whether I'd need an extra vlan capable switch down the road, with 1 pc plugged into (in my case) LAN port 2, that should be vlan-nable within the AC87U, right
2) regarding firewall on NAS: good solution, but what about other IoT devices that I doesn't want my NVR/Ip camera's talk with. You can't block them all.
3) good solution, although if my NVR/camera's would be wifi, that would be a good alternative, but here I'm aiming for "LAN" separation. And from what I understood: vlans is way to go, with on top ebtables filtering on top of iptables filtering.
I'm not sure whether I'd need an extra vlan capable switch down the road, with 1 pc plugged into (in my case) LAN port 2, that should be vlan-nable within the AC87U, right
Thanks @Martineau ! Indeed, I figured out the port 5 and 7 are the "special" ports on the AC87U.
It has been a long time ago since I played with my Cisco CCNP/CCNA stuff, but I'm not following you on the advantage of using a VLAN Capable switch: In that case, I would make eg port 3 tagged on the AC87U, and untag it at the other switch and patch cameras/NVR in. However, my WAN would need to strip only that vlan off port 0. Which makes it impossible for connecting from LAN to the CCTV Vlan, unless all LAN devices need to VPN through WAN-OpenVPN and hop-off into the CCTV Vlan.
I found another interesting article on how to put a fixed IP on the LAN port interface, and work through the routing table and "fix"/"block" traffic accordingly. But that would be lots of trial and error lol.
Thank you and have a nice day!
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.