Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:firewall:fw3_configurations:fw3_parent_controls [2020/07/26 22:20] – [Blocking IPs based on their domain names (FQDN, host names)] added link to DNS hijacking vgaetera | docs:guide-user:firewall:fw3_configurations:fw3_parent_controls [2023/08/30 08:26] – [Blocking services with banIP] vgaetera | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| {{section> | {{section> | ||
| - | Parental control of internet access can be done in several ways: | + | ===== Introduction ===== |
| - | * Timely restriction | + | * This article describes common methods to perform parental control |
| - | * Restrict / deny / block access | + | * Be sure to apply restrictions to all source zones if you are using a firewall-based method. |
| - | * Blocking Servers by blocking Static IPs | + | |
| - | * Blocking Name resolution (DNS) by Adblockers | + | |
| - | * Blocking IPs based on their Domainnames (FQDN, Hostnames) | + | |
| - | * Blocking sites by using Proxy Servers | + | |
| ===== Restrict / deny / block access to certain web pages ===== | ===== Restrict / deny / block access to certain web pages ===== | ||
| - | ==== Blocking | + | ==== Blocking |
| - | If a server is running at a single IP or just uses a small set of IPs, blocking these IPs in fw3 is a very efficient way to block this site. It is the quickest and most efficient way of blocking websites and is well supported even in the Webinterface. Assuming | + | Follow: |
| - | ASN lists could be used to block large numbers of IPs belonging to certain companies. A script would be used to fetch all current IPs assigned to a certain company and this information is used to update the firewall accordingly. | + | [[docs: |
| + | |||
| + | If a server is running at a single IP or just uses a small set of IPs, blocking these IPs in fw3 is a very efficient way to block this site. | ||
| + | It is the quickest and most efficient way of blocking websites and is well supported even in the web interface. | ||
| + | Assuming | ||
| + | ASN lists could be used to block large numbers of IPs belonging to certain companies. | ||
| + | A script would be used to fetch all current IPs assigned to a certain company and this information is used to update the firewall accordingly. | ||
| Drawbacks: | Drawbacks: | ||
| - | * To circumvent these IP based restrictions an internet proxy or TOR could be used. | + | * To circumvent these IP based restrictions an internet proxy or Tor could be used. |
| * Dynamic hosts change their IP on a regular basis, invalidating the blacklist | * Dynamic hosts change their IP on a regular basis, invalidating the blacklist | ||
| - | ==== Blocking | + | ==== Blocking |
| - | This method voids DNS lookups so, for example, '' | + | Follow: |
| + | [[docs: | ||
| + | [[docs: | ||
| + | |||
| + | This method voids DNS lookups so, for example, '' | ||
| + | Adblock | ||
| + | Alternatively | ||
| + | Another option is to use Pi-hole | ||
| Drawbacks: | Drawbacks: | ||
| Line 28: | Line 37: | ||
| ==== Blocking IPs based on their domain names (FQDN, host names) ==== | ==== Blocking IPs based on their domain names (FQDN, host names) ==== | ||
| + | Follow: | ||
| + | [[docs: | ||
| + | |||
| Since OpenWrt in a typical setup with a LAN and WAN zone does the name resolution and the firewall at the same time, all information is there to match domain names, their current IPs as they are handed out to the LAN-hosts and act accordingly in the firewall. | Since OpenWrt in a typical setup with a LAN and WAN zone does the name resolution and the firewall at the same time, all information is there to match domain names, their current IPs as they are handed out to the LAN-hosts and act accordingly in the firewall. | ||
| This is essential if a single domain might resolve to several IPs. | This is essential if a single domain might resolve to several IPs. | ||
| For instance websites that operate with a CDN can be blocked by their name instead of finding out each and every IP the CDN might be using. | For instance websites that operate with a CDN can be blocked by their name instead of finding out each and every IP the CDN might be using. | ||
| - | An example to block domains | + | Drawbacks: |
| + | * This will block all sites sharing the same IP with the targeted, so use carefully for domains | ||
| + | * Completely blocking sites that use localized domains is problematic. | ||
| + | |||
| + | ==== Blocking services with banIP ==== | ||
| + | See also: | ||
| + | [[packages: | ||
| + | [[packages: | ||
| + | |||
| + | banIP can block services using IP/CIDR lists, e.g. you can block WhatsApp with [[https:// | ||
| <code bash> | <code bash> | ||
| - | # Install packages | ||
| opkg update | opkg update | ||
| - | opkg remove dnsmasq | + | opkg install |
| - | opkg install | + | uci set banip.global.ban_enabled="1" |
| - | + | uci del_list banip.global.ban_feed="whatsapp" | |
| - | # Configure IP sets for domains to block | + | uci add_list banip.global.ban_feed="whatsapp" |
| - | uci -q delete firewall.block | + | uci commit banip |
| - | uci set firewall.block=" | + | . / |
| - | uci set firewall.block.name="block" | + | json_init |
| - | uci set firewall.block.family="ipv4" | + | json_load_file / |
| - | uci set firewall.block.storage="hash" | + | json_add_object |
| - | uci set firewall.block.match=" | + | json_add_string |
| - | uci -q delete firewall.block6 | + | json_add_string |
| - | uci set firewall.block6=" | + | HybridNetworks/ |
| - | uci set firewall.block6.name=" | + | json_add_string |
| - | uci set firewall.block6.family=" | + | json_close_object |
| - | uci set firewall.block6.storage="hash" | + | json_dump > /etc/banip/banip.custom.feeds |
| - | uci set firewall.block6.match="ip" | + | / |
| - | + | ||
| - | # Block forward traffic with destination matching IP sets | + | |
| - | uci -q delete firewall.block_fwd | + | |
| - | uci set firewall.block_fwd="rule" | + | |
| - | uci set firewall.block_fwd.name="Block-Example-Domains" | + | |
| - | uci set firewall.block_fwd.src="lan" | + | |
| - | uci set firewall.block_fwd.dest=" | + | |
| - | uci set firewall.block_fwd.family=" | + | |
| - | uci set firewall.block_fwd.proto=" | + | |
| - | uci set firewall.block_fwd.ipset=" | + | |
| - | uci set firewall.block_fwd.target=" | + | |
| - | uci -q delete firewall.block6_fwd | + | |
| - | uci set firewall.block6_fwd=" | + | |
| - | uci set firewall.block6_fwd.name="Block-Example-Domains" | + | |
| - | uci set firewall.block6_fwd.src="lan" | + | |
| - | uci set firewall.block6_fwd.dest="wan" | + | |
| - | uci set firewall.block6_fwd.family=" | + | |
| - | uci set firewall.block6_fwd.proto=" | + | |
| - | uci set firewall.block6_fwd.ipset=" | + | |
| - | uci set firewall.block6_fwd.target=" | + | |
| - | uci commit firewall | + | |
| - | /etc/init.d/firewall restart | + | |
| - | + | ||
| - | # Configure domains to block | + | |
| - | uci -q delete dhcp.dnsmasq[0].ipset | + | |
| - | uci add_list dhcp.dnsmasq[0].ipset="/ | + | |
| - | uci add_list dhcp.dnsmasq[0].ipset="/ | + | |
| - | uci commit dhcp | + | |
| - | / | + | |
| </ | </ | ||
| - | See also: [[docs: | + | ==== Blocking sites by using proxy servers ===== |
| + | Follow: | ||
| + | [[docs: | ||
| - | To observe the filtering taking place enable logging to the syslog for the DHCP server | + | A proxy server |
| - | Another handy command is '' | + | It can check HTTP(S) specific details. |
| - | + | The huge benefit of this option is to have the finest level of control. | |
| - | Drawbacks: | + | It can even distinguish |
| - | * If servers are multi-homed its not possible | + | |
| - | * Not supported | + | |
| - | ==== Blocking sites by using Proxy Servers ===== | + | Squid offers many features |
| - | A proxy server | + | |
| Drawbacks: | Drawbacks: | ||
| - | | + | * If not everything else except the proxy is blocked, it can be circumvented. The firewall must block the client-device from accessing the internet directly. |
| - | * Complex setup | + | * The clients need to configure the proxy in their browser. |
| - | | + | |
| - | ===== Timely | + | ===== Time restriction of internet access ===== |
| - | **Example: | + | Block internet access for MAC or IP addresses (or everyone) |
| - | ==== Web interface ==== | + | <WRAP important> |
| - | First, make sure that your router has the right time **and** the right timezone. | + | * Verify |
| - | + | | |
| - | <WRAP group> | + | * [[docs: |
| - | <WRAP half column> | + | * [[docs: |
| - | | + | |
| - | - Add name for your rule, e.g. "Kids weeksdays", | + | |
| - | - Source zone: lan | + | |
| - | | + | |
| - | - Click //Add and edit// | + | |
| - | - Select //Source MAC address// or //Source address// | + | |
| - | - Set // | + | |
| - | | + | |
| - | - Select start/stop time | + | |
| - | - Save& | + | |
| </ | </ | ||
| - | <WRAP half column> | + | ==== Web interface instructions ==== |
| - | {{ : | + | Adjust |
| - | </ | + | |
| - | </ | + | |
| - | + | ||
| - | More detailed explanations in French: | + | |
| - | [[https:// | + | |
| - | + | ||
| - | NB: If your focus is on authorised timeslots, you can create a rule that always rejects, and add a few rules that accept for the authorised timeslots. Order the rules so as to bring Accept rules before the Reject rule. | + | |
| - | NB: The stop time will stop kids from creating a **new** connection e.g. to browse one more page on Wikipedia. It will not kick out your kids if they have an existing connection e.g. in an Android game app. To enforce | + | - Navigate to **LuCI -> Network -> Firewall -> Traffic Rules**. |
| + | - Click **Add** and specify: | ||
| + | * Name: '' | ||
| + | * Protocol: Any | ||
| + | * Source zone: '' | ||
| + | * Destination zone: '' | ||
| + | * Action: reject | ||
| + | - (Optional) If you want to add a MAC or IP limitation, | ||
| + | * Source MAC address: '' | ||
| + | * Source IP address: '' | ||
| + | - On the **Time Restrictions** tab specify: | ||
| + | * Week Days: Monday, Tuesday, Wednesday, Thursday, Friday | ||
| + | * Start Time: '' | ||
| + | * Stop Time: '' | ||
| + | - Click **Save**, then **Save & Apply**. | ||
| - | NB: If you have e.g. a Guest network, this rule won't restrict your kid if/when they connect | + | You can add another |
| - | ==== Command-line | + | ==== Command-line |
| Add a new firewall rule. | Add a new firewall rule. | ||
| Edit the following example code block to suit your needs and then copy-paste it into the terminal. | Edit the following example code block to suit your needs and then copy-paste it into the terminal. | ||
| Line 141: | Line 127: | ||
| <code bash> | <code bash> | ||
| + | # Configure firewall | ||
| uci add firewall rule | uci add firewall rule | ||
| - | uci set firewall.@rule[-1].name=" | + | uci set firewall.@rule[-1].name=" |
| uci set firewall.@rule[-1].src=" | uci set firewall.@rule[-1].src=" | ||
| - | uci set firewall.@rule[-1].src_mac=" | + | uci set firewall.@rule[-1].src_mac=" |
| uci set firewall.@rule[-1].dest=" | uci set firewall.@rule[-1].dest=" | ||
| uci set firewall.@rule[-1].start_time=" | uci set firewall.@rule[-1].start_time=" | ||
| uci set firewall.@rule[-1].stop_time=" | uci set firewall.@rule[-1].stop_time=" | ||
| uci set firewall.@rule[-1].weekdays=" | uci set firewall.@rule[-1].weekdays=" | ||
| - | uci set firewall.@rule[-1].utc_time=" | ||
| uci set firewall.@rule[-1].target=" | uci set firewall.@rule[-1].target=" | ||
| uci commit firewall | uci commit firewall | ||
| Line 155: | Line 141: | ||
| </ | </ | ||
| - | Once the time is reached, | + | ===== Restrict access to Wi-Fi by MAC address ===== |
| - | The rules should be reordered | + | Restrict access to your Wi-Fi by MAC address. |
| + | The primary motivation for this capability | ||
| + | Later you no longer want to allow the person to use your Wi-Fi. | ||
| + | There are several solutions to this problem with decreasing labor and effectiveness. | ||
| + | - The most comprehensive is to create a [[docs: | ||
| + | - Change the passphrase for the interfaces. | ||
| + | - Only allow/deny LAN access for devices with matching MAC addresses. | ||
| + | |||
| + | This section focuses on the last option using the wireless interface MAC filter option. | ||
| + | This is a simple solution that can be invalidated by a smart hacker changing the MAC address of their device. | ||
| + | |||
| + | ==== Web interface instructions ==== | ||
| + | - Navigate to **LuCI -> Network -> Wireless**. | ||
| + | - Click **Edit** on a selected interface. | ||
| + | - On the **MAC Address Filter** tab specify: | ||
| + | * MAC Address Filter: | ||
| + | * Allow listed only | ||
| + | * Allow all except listed | ||
| + | * MAC List: | ||
| + | * '' | ||
| + | * '' | ||
| + | - Click **Save**, then **Save & Apply**. | ||
| + | |||
| + | ==== Command-line instructions ==== | ||
| <code bash> | <code bash> | ||
| - | # Reorder iptables/ | + | # Use allow-type or deny-type filter |
| - | cat << " | + | uci set wireless.@wifi-iface[0].macfilter=" |
| - | for IPT in iptables ip6tables | + | uci set wireless.@wifi-iface[0].macfilter="deny" |
| - | do | + | |
| - | ${IPT}-save -c -t filter | + | |
| - | | sed -e "/ | + | |
| - | /FORWARD.*reject/i $(${IPT}-save -c -t filter \ | + | |
| - | | sed -n -e "/ | + | |
| - | | ${IPT}-restore -c -T filter | + | |
| - | done | + | |
| - | EOF | + | |
| - | # Enable | + | # Append |
| - | uci -q delete firewall.estab | + | uci add_list wireless.@wifi-iface[0].maclist="11: |
| - | uci set firewall.estab="include" | + | uci add_list wireless.@wifi-iface[0].maclist="aa: |
| - | uci set firewall.estab.path="/ | + | |
| - | uci set firewall.estab.reload=" | + | |
| - | uci commit firewall | + | |
| - | / | + | |
| - | # Back up the reordering script | + | # Check settings |
| - | cat << EOF >> / | + | uci show wireless.@wifi-iface[0] |
| - | / | + | |
| - | EOF | + | # Save and apply |
| - | </ | + | uci commit wireless |
| + | wifi reload | ||
| + | </ | ||
| + | |||
| + | You need to apply this for all wireless interfaces accessible by the user. | ||
| + | Typically the 5 Ghz band is '' | ||