Sources:
https://gist.github.com/pinkeen/3076cd6f5cc5b08d3faacfa2db149a17
https://www.vanwerkhoven.org/blog/2022/home-network-configuration/
https://justinho.com/blog/2020/09/03/cleanedgerouter.html
https://loganmarchione.com/2016/04/ubiquiti-edgerouter-lite-setup/
https://help.ui.com/hc/en-us/articles/218889067-EdgeRouter-How-to-Create-a-Guest-LAN-Firewall-Rule
https://help.ui.com/hc/en-us/articles/360002231373-EdgeRouter-How-to-Find-the-Base-MAC-Address
We define the following networks:
- WAN - WAN interfaces
- LAN - VLAN 1 (U) - 192.168.10.0/24 - all trusted hosts (PCs, smartphones, tablets, TVs, homeassistant etc) - router, switch
- Guest - VLAN 20 (T) - 192.168.20.0/24 - guest wifi
- IOT - VLAN 30 (T) - 192.168.30.0/24 - smart devices
- DMZ
We define the following zones:
- WAN: internet
- LOCAL: router (er-x.matrix.local), dns, dhcp, switch (usw.matrix.local), wifi (u7ap.matrix.local)
- LAN: trusted network, all wired and wireless hosts, home server (homeassistant, ha.matrix.local) serving http(s), ssh, mqtt, and many more
- GUEST: untrusted network allowed to connect to internet
- IOT: untrusted network allowed to connect to the home server (homeassistant, ha.matrix.local) and IOT cloud hosts
- DMZ: reverse proxy (not defined yet) for home server (homeassistant, ha.matrix.local)
Firewall rules:
--- | to WAN | to LOCAL | to LAN | to GUEST | to IOT | to DMZ |
---|---|---|---|---|---|---|
WAN | - | wan_to_all | wan_to_all | wan_to_all | wan_to_all | TDB |
LOCAL | fw_accept | - | fw_accept | fw_accept | fw_accept | TDB |
LAN | fw_accept | fw_accept | - | fw_accept | fw_accept | TDB |
Guest | fw_accept | guest_to_local | guest_to_lan | - | fw_drop | TDB |
IOT | iot_to_wan | iot_to_local | iot_to_lan | fw_drop | - | TDB |
DMZ | TBD | TBD | TBD | TBD | TBD | - |
Keep last 10 configuration commit revisions (by default none is kept)
See the official docs for verbose info.
set system config-management commit-revisions 10
This allows you later list commits and roll them back.
After fuckup rollback to specific revision\
rollback ? # list commits
rollback {NUM}
Harden services
set service gui listen-address 10.0.0.1
set service gui older-ciphers disable
set service ssh listen-address 10.0.0.1
set service ssh port 22
set service ssh protocol-version v2
Connect to UISP matrixx.uisp.com
https://help.ui.com/hc/en-us/articles/115012196527-UISP-First-Time-Setup-Installation
Install SSL from Let's Encrypt
https://github.com/j-c-m/ubnt-letsencrypt
https://thehomeofthefuture.com/installation-guide/set-up-an-ubiquiti-edgerouter-from-scratch/
# Get current configuration
show configuration commands
configure
set system conntrack expect-table-size 4096
set system conntrack hash-size 4096
set system conntrack table-size 32768
set system conntrack tcp half-open-connections 512
set system conntrack tcp loose enable
set system conntrack tcp max-retrans 3
set system analytics-handler send-analytics-report false
set system crash-handler send-crash-report false
set system host-name er-x
set system login user simsim authentication encrypted-password '$5$GzaxeALmDwwUVsIn$1.8BstbMd7IHI23lILPW2Nt/EITe4e0cpBrxA31cYaD'
set system login user simsim level admin
set system ntp server 0.ua.pool.ntp.org
set system ntp server 1.ua.pool.ntp.org
set system syslog global facility all level notice
set system syslog global facility protocols level debug
set system time-zone Europe/Kiev
set system offload hwnat enable
set system offload ipsec enable
set system domain-name matrix.local
set system systemd journal
set system traffic-analysis dpi enable
set system traffic-analysis export enable
set service gui http-port 80
set service gui https-port 443
set service gui older-ciphers disable
set service ssh port 22
set service ssh protocol-version v2
set service unms disable
set service ubnt-discover disable
commit; save; exit
reboot now
configure
set firewall all-ping enable
set firewall broadcast-ping disable
set firewall ipv6-receive-redirects disable
set firewall ipv6-src-route disable
set firewall ip-src-route disable
set firewall log-martians disable
set firewall receive-redirects disable
set firewall send-redirects enable
set firewall source-validation disable
set firewall syn-cookies enable
set firewall group network-group PRIVATE_NETS network 192.168.0.0/16
set firewall group network-group PRIVATE_NETS network 172.16.0.0/12
set firewall group network-group PRIVATE_NETS network 10.0.0.0/8
set firewall modify balance rule 10 action modify
set firewall modify balance rule 10 description 'do NOT load balance lan to lan'
set firewall modify balance rule 10 destination group network-group PRIVATE_NETS
set firewall modify balance rule 10 modify table main
set firewall modify balance rule 50 action modify
set firewall modify balance rule 50 description 'do NOT load balance destination public address'
set firewall modify balance rule 50 destination group address-group ADDRv4_eth3
set firewall modify balance rule 50 modify table main
set firewall modify balance rule 60 action modify
set firewall modify balance rule 60 description 'do NOT load balance destination public address'
set firewall modify balance rule 60 destination group address-group ADDRv4_eth4
set firewall modify balance rule 60 modify table main
set firewall modify balance rule 70 action modify
set firewall modify balance rule 70 modify lb-group G
set load-balance group G exclude-local-dns disable
set load-balance group G flush-on-active enable
set load-balance group G gateway-update-interval 20
set load-balance group G interface eth3
set load-balance group G interface eth4
set load-balance group G lb-local enable
set load-balance group G lb-local-metric-change disable
set load-balance group G exclude-local-dns disable
set load-balance group G flush-on-active enable
set load-balance group G gateway-update-interval 20
set load-balance group G interface eth3 failover-only
set load-balance group G interface eth3 route-test count failure 3
set load-balance group G interface eth3 route-test count success 3
set load-balance group G interface eth3 route-test initial-delay 1
set load-balance group G interface eth3 route-test interval 10
set load-balance group G interface eth3 route-test type ping target 1.1.1.1
set load-balance group G interface eth4 route-test count failure 3
set load-balance group G interface eth4 route-test count success 3
set load-balance group G interface eth4 route-test initial-delay 1
set load-balance group G interface eth4 route-test interval 10
set load-balance group G interface eth4 route-test type ping target 1.1.1.1
set load-balance group G lb-local enable
set load-balance group G lb-local-metric-change disable
commit; save;
set interfaces ethernet eth0 description USW
set interfaces ethernet eth0 duplex auto
set interfaces ethernet eth0 speed auto
set interfaces ethernet eth1 duplex auto
set interfaces ethernet eth1 speed auto
set interfaces ethernet eth2 duplex auto
set interfaces ethernet eth2 speed auto
set interfaces ethernet eth3 address dhcp
set interfaces ethernet eth3 description WAN_IT-TV
set interfaces ethernet eth3 duplex auto
set interfaces ethernet eth3 speed auto
set interfaces ethernet eth4 address dhcp
set interfaces ethernet eth4 description WAN_VEGA
set interfaces ethernet eth4 duplex auto
set interfaces ethernet eth4 poe output off
set interfaces ethernet eth4 speed auto
set interfaces loopback lo
delete interfaces ethernet eth1 address dhcp
set interfaces switch switch0 firewall in modify balance
set interfaces switch switch0 mtu 1500
set interfaces switch switch0 switch-port interface eth1
set interfaces switch switch0 switch-port interface eth2
set interfaces switch switch0 vif 1 address 192.168.10.1/24
set interfaces switch switch0 vif 1 description LAN
set interfaces switch switch0 vif 20 address 192.168.20.1/24
set interfaces switch switch0 vif 20 description Guest
set interfaces switch switch0 vif 30 address 192.168.30.1/24
set interfaces switch switch0 vif 30 description IoT
set interfaces switch switch0 switch-port vlan-aware enable
set interfaces switch switch0 switch-port interface eth1 vlan pvid 1
set interfaces switch switch0 switch-port interface eth2 vlan pvid 1
commit; save;
set service dhcp-server disabled false
set service dhcp-server hostfile-update disable
set service dhcp-server shared-network-name LAN_PVID1 authoritative enable
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 start 192.168.10.100 stop 192.168.10.254
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 default-router 192.168.10.1
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 dns-server 192.168.10.1
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 domain-name matrix.local
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Ring-ChimePro ip-address 192.168.10.66
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Ring-ChimePro mac-address '54:e0:19:5f:04:6c'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Ring-Doorbell ip-address 192.168.10.99
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Ring-Doorbell mac-address '54:e0:19:18:ef:c4'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Kitchen-Sonoff-DualR3 ip-address 192.168.10.31
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Kitchen-Sonoff-DualR3 mac-address 'a0:b7:65:56:3d:f4'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping ToiletSonoff-DualR3 ip-address 192.168.10.36
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Toilet-Sonoff-DualR3 mac-address '08:3a:f2:2b:e4:30'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Toilet-TP-Link-P110_Plug ip-address 192.168.10.64
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Toilet-TP-Link-P110_Plug mac-address '48:22:54:3e:59:a4'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping U7AP ip-address 192.168.10.10
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping U7AP mac-address '28:70:4e:6e:e0:77'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping USW ip-address 192.168.10.5
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping USW mac-address '9c:05:d6:e0:74:e2'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Kitchen-Bosch-Dishwasher ip-address 192.168.10.11
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping Kitchen-Bosch-Dishwasher mac-address '38:b4:d3:f1:33:3b'
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping My-Yeelink-Ceiling22 ip-address 192.168.10.57
set service dhcp-server shared-network-name LAN_PVID1 subnet 192.168.10.0/24 static-mapping My-Yeelink-Ceiling22 mac-address '54:48:e6:63:f3:0f'
set service dhcp-server shared-network-name GUEST_VID20 authoritative enable
set service dhcp-server shared-network-name GUEST_VID20 subnet 192.168.20.0/24 start 192.168.20.100 stop 192.168.20.254
set service dhcp-server shared-network-name GUEST_VID20 subnet 192.168.20.0/24 default-router 192.168.20.1
set service dhcp-server shared-network-name GUEST_VID20 subnet 192.168.20.0/24 dns-server 192.168.20.1
set service dhcp-server shared-network-name GUEST_VID20 subnet 192.168.20.0/24 domain-name matrix.local
set service dhcp-server shared-network-name IOT_VID30 authoritative enable
set service dhcp-server shared-network-name IOT_VID30 subnet 192.168.30.0/24 start 192.168.30.100 stop 192.168.30.254
set service dhcp-server shared-network-name IOT_VID30 subnet 192.168.30.0/24 default-router 192.168.30.1
set service dhcp-server shared-network-name IOT_VID30 subnet 192.168.30.0/24 dns-server 192.168.30.1
set service dhcp-server shared-network-name IOT_VID30 subnet 192.168.30.0/24 domain-name matrix.local
set service dhcp-server static-arp disable
set service dhcp-server use-dnsmasq enable
commit; save;
set service dns forwarding listen-on switch0.1
set service dns forwarding listen-on switch0.20
set service dns forwarding listen-on switch0.30
set service dns forwarding cache-size 1500
set service dns forwarding options bogus-priv
set service dns forwarding options domain-needed
set service dns forwarding options enable-ra
set service dns forwarding options localise-queries
set service dns forwarding options expand-hosts
set service dns forwarding options strict-order
set service dns forwarding options address=/matrix.local/192.168.10.1
set system static-host-mapping host-name er-x.matrix.local inet 192.168.10.1
set system static-host-mapping host-name usw.matrix.local inet 192.168.10.5
set system static-host-mapping host-name u7ap.matrix.local inet 192.168.10.10
set system static-host-mapping host-name hass.matrix.local inet 192.168.10.50
set service nat rule 5006 description 'masquerade for WAN_IT-TV'
set service nat rule 5006 outbound-interface eth3
set service nat rule 5006 type masquerade
set service nat rule 5008 description 'masquerade for WAN_VEGA'
set service nat rule 5008 outbound-interface eth4
set service nat rule 5008 type masquerade
set service nat rule 5006 log disable
set service nat rule 5006 protocol all
set service nat rule 5008 log disable
set service nat rule 5008 protocol all
commit; save;
### WAN to LAN, LOCAL
set firewall name WAN_TO_ALL default-action drop
set firewall name WAN_TO_ALL rule 10 action accept
set firewall name WAN_TO_ALL rule 10 description 'accept established/related'
set firewall name WAN_TO_ALL rule 10 state established enable
set firewall name WAN_TO_ALL rule 10 state related enable
set firewall name WAN_TO_ALL rule 100 action drop
set firewall name WAN_TO_ALL rule 100 description 'drop invalid'
set firewall name WAN_TO_ALL rule 100 state invalid enable
### FW_ACCEPT
set firewall name FW_ACCEPT default-action accept
### FW_DROP
set firewall name FW_DROP default-action drop
### GUEST to LOCAL
set firewall name GUEST_TO_LOCAL default-action drop
set firewall name GUEST_TO_LOCAL rule 10 action accept
set firewall name GUEST_TO_LOCAL rule 10 description 'accept dns'
set firewall name GUEST_TO_LOCAL rule 10 log disable
set firewall name GUEST_TO_LOCAL rule 10 protocol udp
set firewall name GUEST_TO_LOCAL rule 10 destination port 53
set firewall name GUEST_TO_LOCAL rule 20 action accept
set firewall name GUEST_TO_LOCAL rule 20 description 'accept dhcp'
set firewall name GUEST_TO_LOCAL rule 20 log disable
set firewall name GUEST_TO_LOCAL rule 20 protocol udp
set firewall name GUEST_TO_LOCAL rule 20 destination port 67-68
set firewall name GUEST_TO_LOCAL rule 30 action drop
set firewall name GUEST_TO_LOCAL rule 30 description 'drop invalid'
set firewall name GUEST_TO_LOCAL rule 30 state invalid enable
### GUEST to LAN
set firewall name GUEST_TO_LAN default-action drop
set firewall name GUEST_TO_LAN rule 10 action accept
set firewall name GUEST_TO_LAN rule 10 description 'accept established/related'
set firewall name GUEST_TO_LAN rule 10 log disable
set firewall name GUEST_TO_LAN rule 10 state established enable
set firewall name GUEST_TO_LAN rule 10 state related enable
set firewall name GUEST_TO_LAN rule 20 action accept
set firewall name GUEST_TO_LAN rule 20 description 'accept https to HomeAssistant'
set firewall name GUEST_TO_LAN rule 20 log disable
set firewall name GUEST_TO_LAN rule 20 protocol tcp
set firewall name GUEST_TO_LAN rule 20 destination port 443
set firewall name GUEST_TO_LAN rule 20 destination address 192.168.10.50
set firewall name GUEST_TO_LAN rule 100 action drop
set firewall name GUEST_TO_LAN rule 100 description 'drop invalid'
set firewall name GUEST_TO_LAN rule 100 state invalid enable
### IOT to WAN
set firewall name IOT_TO_WAN default-action accept
### IOT to LOCAL
set firewall name IOT_TO_LOCAL default-action drop
set firewall name IOT_TO_LOCAL rule 10 action accept
set firewall name IOT_TO_LOCAL rule 10 description 'accept dns'
set firewall name IOT_TO_LOCAL rule 10 log disable
set firewall name IOT_TO_LOCAL rule 10 protocol udp
set firewall name IOT_TO_LOCAL rule 10 destination port 53
set firewall name IOT_TO_LOCAL rule 20 action accept
set firewall name IOT_TO_LOCAL rule 20 description 'accept dhcp'
set firewall name IOT_TO_LOCAL rule 20 log disable
set firewall name IOT_TO_LOCAL rule 20 protocol udp
set firewall name IOT_TO_LOCAL rule 20 destination port 67-68
set firewall name IOT_TO_LOCAL rule 30 action drop
set firewall name IOT_TO_LOCAL rule 30 description 'drop invalid'
set firewall name IOT_TO_LOCAL rule 30 state invalid enable
### IOT to LAN
set firewall name IOT_TO_LAN default-action accept
commit; save;
### Enable policies
set zone-policy zone WAN1 interface eth3
set zone-policy zone WAN1 default-action drop
set zone-policy zone WAN1 from LOCAL firewall name FW_ACCEPT
set zone-policy zone WAN1 from LAN firewall name FW_ACCEPT
set zone-policy zone WAN1 from GUEST firewall name FW_ACCEPT
set zone-policy zone WAN1 from IOT firewall name IOT_TO_WAN
set zone-policy zone WAN1 from WAN2 firewall name FW_DROP
set zone-policy zone WAN2 interface eth4
set zone-policy zone WAN2 default-action drop
set zone-policy zone WAN2 from LOCAL firewall name FW_ACCEPT
set zone-policy zone WAN2 from LAN firewall name FW_ACCEPT
set zone-policy zone WAN2 from GUEST firewall name FW_ACCEPT
set zone-policy zone WAN2 from IOT firewall name IOT_TO_WAN
set zone-policy zone WAN2 from WAN1 firewall name FW_DROP
set zone-policy zone LOCAL local-zone
set zone-policy zone LOCAL default-action drop
set zone-policy zone LOCAL from IOT firewall name IOT_TO_LOCAL
set zone-policy zone LOCAL from WAN1 firewall name WAN_TO_ALL
set zone-policy zone LOCAL from WAN2 firewall name WAN_TO_ALL
set zone-policy zone LOCAL from LAN firewall name FW_ACCEPT
set zone-policy zone LOCAL from GUEST firewall name GUEST_TO_LOCAL
set zone-policy zone LAN interface switch0.1
set zone-policy zone LAN default-action drop
set zone-policy zone LAN from WAN1 firewall name WAN_TO_ALL
set zone-policy zone LAN from WAN2 firewall name WAN_TO_ALL
set zone-policy zone LAN from LOCAL firewall name FW_ACCEPT
set zone-policy zone LAN from GUEST firewall name GUEST_TO_LAN
set zone-policy zone LAN from IOT firewall name IOT_TO_LAN
set zone-policy zone GUEST interface switch0.20
set zone-policy zone GUEST default-action drop
set zone-policy zone GUEST from WAN1 firewall name WAN_TO_ALL
set zone-policy zone GUEST from WAN2 firewall name WAN_TO_ALL
set zone-policy zone GUEST from LOCAL firewall name FW_ACCEPT
set zone-policy zone GUEST from LAN firewall name FW_ACCEPT
set zone-policy zone GUEST from IOT firewall name FW_DROP
set zone-policy zone IOT interface switch0.30
set zone-policy zone IOT default-action drop
set zone-policy zone IOT from WAN1 firewall name WAN_TO_ALL
set zone-policy zone IOT from WAN2 firewall name WAN_TO_ALL
set zone-policy zone IOT from LOCAL firewall name FW_ACCEPT
set zone-policy zone IOT from LAN firewall name FW_ACCEPT
set zone-policy zone IOT from GUEST firewall name FW_DROP
commit; save;
########################################################################
### Reconnect link to eth1 ###
### Set Obtain an IP address automatically ###
### Reconnect to the router via IP 192.168.10.1 ###
########################################################################
configure
delete interfaces ethernet eth0 address
set interfaces switch switch0 switch-port interface eth0
set interfaces switch switch0 switch-port interface eth0 vlan pvid 1
set interfaces switch switch0 switch-port interface eth0 vlan vid 20
set interfaces switch switch0 switch-port interface eth0 vlan vid 30
commit; save; exit
reboot now