140-firewall-rules 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/lua
  2. local uci = require('simple-uci').cursor()
  3. local function reject_input_on_wan(zone)
  4. if zone.name == 'wan' then
  5. uci:set('firewall', zone['.name'], 'input', 'REJECT')
  6. uci:set('firewall', zone['.name'], 'conntrack', true)
  7. end
  8. return true
  9. end
  10. uci:foreach('firewall', 'zone', reject_input_on_wan)
  11. for _, zone in ipairs ({ 'mesh', 'local_client' } ) do
  12. -- Other packages assign interfaces to these zones
  13. uci:section('firewall', 'zone', zone, {
  14. name = zone,
  15. network = {},
  16. input = 'REJECT',
  17. output = 'ACCEPT',
  18. forward = 'REJECT',
  19. })
  20. uci:section('firewall', 'rule', zone .. '_ICMPv6_in', {
  21. src = zone,
  22. proto = 'icmp',
  23. icmp_type = {
  24. 'echo-request',
  25. 'echo-reply',
  26. 'destination-unreachable',
  27. 'packet-too-big',
  28. 'time-exceeded',
  29. 'bad-header',
  30. 'unknown-header-type',
  31. 'router-solicitation',
  32. 'neighbour-solicitation',
  33. 'router-advertisement',
  34. 'neighbour-advertisement',
  35. '130/0', -- Multicast Listener Query
  36. '131/0', -- Multicast Listener Report
  37. '132/0', -- Multicast Listener Done
  38. '143/0', -- MLDv2
  39. },
  40. limit = '1000/sec',
  41. family = 'ipv6',
  42. target = 'ACCEPT',
  43. })
  44. -- Can be removed soon: was never in a release
  45. uci:delete('firewall', zone .. '_ICMPv6_out')
  46. end
  47. uci:section('firewall', 'rule', 'local_client_ICMPv4_in', {
  48. src = 'local_client',
  49. proto = 'icmp',
  50. icmp_type = {
  51. 'echo-request',
  52. },
  53. family = 'ipv4',
  54. target = 'ACCEPT',
  55. })
  56. -- allow inbound SSH from anywhere
  57. for _, zone in ipairs({ 'wan', 'local_client', 'mesh' }) do
  58. uci:section('firewall', 'rule', zone .. '_ssh', {
  59. name = zone .. '_ssh',
  60. src = zone,
  61. dest_port = '22',
  62. proto = 'tcp',
  63. target = 'ACCEPT',
  64. })
  65. end
  66. uci:save('firewall')