[操作疑難] openwrt firewall 問題

各位Ching,我試用openwrt firewall "Traffic Rules"去加可以由wan用ssh 去router,但我發覺好似firewall無開到個port 22.
  1. config rule                  
  2.         option target 'ACCEPT'        
  3.         option src 'wan'              
  4.         option proto 'tcp'     
  5.         option dest_port '22'  
  6.         option name 'accept-ssh-wan-service'
  7.         option dest_ip '192.168.1.1'
  8.         option enabled '1'
複製代碼
如果用 "Port Forwards" 加條rule, 就可以開到
  1. config redirect               
  2.         option target 'DNAT'         
  3.         option src 'wan'      
  4.         option dest 'lan'
  5.         option proto 'tcp'        
  6.         option src_dport '22'      
  7.         option dest_ip '192.168.1.1'
  8.         option dest_port '22'         
  9.         option name 'wan-ssh'
複製代碼
係唔係唔應該係"Traffic Rules" set? 定我做錯config? 有無ching指教一下

iptables -L
之後貼上來

via HKEPC IR Pro 3.6.1 - iOS(3.0.0)

TOP

Ching, 唔該睇下有無建議
  1. Chain INPUT (policy ACCEPT)
  2. target     prot opt source               destination
  3. ACCEPT     all  --  anywhere             anywhere             /* !fw3 */
  4. input_rule  all  --  anywhere             anywhere             /* !fw3: Custom input rule chain */
  5. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  6. DROP       all  --  anywhere             anywhere             ctstate INVALID /* !fw3 */
  7. syn_flood  tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,ACK/SYN /* !fw3 */
  8. zone_lan_input  all  --  anywhere             anywhere             /* !fw3 */
  9. zone_wan_input  all  --  anywhere             anywhere             /* !fw3 */
  10. zone_dmz_input  all  --  anywhere             anywhere             /* !fw3 */

  11. Chain FORWARD (policy DROP)
  12. target     prot opt source               destination
  13. forwarding_rule  all  --  anywhere             anywhere             /* !fw3: Custom forwarding rule chain */
  14. FLOWOFFLOAD  all  --  anywhere             anywhere             /* !fw3: Traffic offloading */ ctstate RELATED,ESTABLISHED FLOWOFFLOAD hw
  15. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  16. @
  17. "iptables.txt" 180L, 10529C
  18. Chain INPUT (policy ACCEPT)
  19. target     prot opt source               destination
  20. ACCEPT     all  --  anywhere             anywhere             /* !fw3 */
  21. input_rule  all  --  anywhere             anywhere             /* !fw3: Custom input rule chain */
  22. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  23. DROP       all  --  anywhere             anywhere             ctstate INVALID /* !fw3 */
  24. syn_flood  tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,ACK/SYN /* !fw3 */
  25. zone_lan_input  all  --  anywhere             anywhere             /* !fw3 */
  26. zone_wan_input  all  --  anywhere             anywhere             /* !fw3 */
  27. zone_dmz_input  all  --  anywhere             anywhere             /* !fw3 */

  28. Chain FORWARD (policy DROP)
  29. target     prot opt source               destination
  30. forwarding_rule  all  --  anywhere             anywhere             /* !fw3: Custom forwarding rule chain */
  31. FLOWOFFLOAD  all  --  anywhere             anywhere             /* !fw3: Traffic offloading */ ctstate RELATED,ESTABLISHED FLOWOFFLOAD hw
  32. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  33. DROP       all  --  anywhere             anywhere             ctstate INVALID /* !fw3 */
  34. zone_lan_forward  all  --  anywhere             anywhere             /* !fw3 */
  35. zone_wan_forward  all  --  anywhere             anywhere             /* !fw3 */
  36. zone_dmz_forward  all  --  anywhere             anywhere             /* !fw3 */
  37. reject     all  --  anywhere             anywhere             /* !fw3 */

  38. Chain OUTPUT (policy ACCEPT)
  39. Chain INPUT (policy ACCEPT)
  40. target     prot opt source               destination
  41. ACCEPT     all  --  anywhere             anywhere             /* !fw3 */
  42. input_rule  all  --  anywhere             anywhere             /* !fw3: Custom input rule chain */
  43. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  44. DROP       all  --  anywhere             anywhere             ctstate INVALID /* !fw3 */
  45. syn_flood  tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,ACK/SYN /* !fw3 */
  46. zone_lan_input  all  --  anywhere             anywhere             /* !fw3 */
  47. zone_wan_input  all  --  anywhere             anywhere             /* !fw3 */
  48. zone_dmz_input  all  --  anywhere             anywhere             /* !fw3 */

  49. Chain FORWARD (policy DROP)
  50. target     prot opt source               destination
  51. forwarding_rule  all  --  anywhere             anywhere             /* !fw3: Custom forwarding rule chain */
  52. FLOWOFFLOAD  all  --  anywhere             anywhere             /* !fw3: Traffic offloading */ ctstate RELATED,ESTABLISHED FLOWOFFLOAD hw
  53. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  54. DROP       all  --  anywhere             anywhere             ctstate INVALID /* !fw3 */
  55. zone_lan_forward  all  --  anywhere             anywhere             /* !fw3 */
  56. zone_wan_forward  all  --  anywhere             anywhere             /* !fw3 */
  57. zone_dmz_forward  all  --  anywhere             anywhere             /* !fw3 */
  58. reject     all  --  anywhere             anywhere             /* !fw3 */

  59. Chain OUTPUT (policy ACCEPT)
  60. target     prot opt source               destination
  61. Chain INPUT (policy ACCEPT)
  62. target     prot opt source               destination
  63. ACCEPT     all  --  anywhere             anywhere             /* !fw3 */
  64. input_rule  all  --  anywhere             anywhere             /* !fw3: Custom input rule chain */
  65. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  66. DROP       all  --  anywhere             anywhere             ctstate INVALID /* !fw3 */
  67. syn_flood  tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,ACK/SYN /* !fw3 */
  68. zone_lan_input  all  --  anywhere             anywhere             /* !fw3 */
  69. zone_wan_input  all  --  anywhere             anywhere             /* !fw3 */
  70. zone_dmz_input  all  --  anywhere             anywhere             /* !fw3 */

  71. Chain FORWARD (policy DROP)
  72. target     prot opt source               destination
  73. forwarding_rule  all  --  anywhere             anywhere             /* !fw3: Custom forwarding rule chain */
  74. FLOWOFFLOAD  all  --  anywhere             anywhere             /* !fw3: Traffic offloading */ ctstate RELATED,ESTABLISHED FLOWOFFLOAD hw
  75. ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED /* !fw3 */
  76. DROP       all  --  anywhere             anywhere             ctstate INVALID /* !fw3 */
  77. zone_lan_forward  all  --  anywhere             anywhere             /* !fw3 */
  78. zone_wan_forward  all  --  anywhere             anywhere             /* !fw3 */
  79. zone_dmz_forward  all  --  anywhere             anywhere             /* !fw3 */
  80. reject     all  --  anywhere             anywhere             /* !fw3 */

  81. Chain OUTPUT (policy ACCEPT)
  82. target     prot opt source               destination
  83. ACCEPT     all  --  anywhere             anywhere             /* !fw3 */

  84. Chain zone_wan_dest_REJECT (1 references)
  85. target     prot opt source               destination
  86. reject     all  --  anywhere             anywhere             /* !fw3 */

  87. Chain zone_wan_forward (1 references)
  88. target     prot opt source               destination
  89. forwarding_wan_rule  all  --  anywhere             anywhere             /* !fw3: Custom wan forwarding rule chain */
  90. zone_lan_dest_ACCEPT  esp  --  anywhere             anywhere             /* !fw3: Allow-IPSec-ESP */
  91. zone_lan_dest_ACCEPT  udp  --  anywhere             anywhere             udp dpt:isakmp /* !fw3: Allow-ISAKMP */
  92. ACCEPT     all  --  anywhere             anywhere             ctstate DNAT /* !fw3: Accept port forwards */
  93. MINIUPNPD  all  --  anywhere             anywhere
  94. zone_wan_dest_REJECT  all  --  anywhere             anywhere             /* !fw3 */

  95. Chain zone_wan_input (1 references)
  96. target     prot opt source               destination
  97. input_wan_rule  all  --  anywhere             anywhere             /* !fw3: Custom wan input rule chain */
  98. ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootpc /* !fw3: Allow-DHCP-Renew */
  99. ACCEPT     icmp --  anywhere             anywhere             icmp echo-request /* !fw3: Allow-Ping */
  100. ACCEPT     igmp --  anywhere             anywhere             /* !fw3: Allow-IGMP */
  101. ACCEPT     udp  --  anywhere             newifi.lan           udp dpt:domain /* !fw3: dmz-dns */
  102. ACCEPT     udp  --  anywhere             newifi.lan           udp dpt:bootps /* !fw3: dmz-dhcp */
  103. ACCEPT     tcp  --  anywhere             newifi.lan           tcp dpt:ssh /* !fw3: accept-ssh-wan-service */
  104. ACCEPT     all  --  anywhere             anywhere             ctstate DNAT /* !fw3: Accept port redirections */
  105. zone_wan_src_REJECT  all  --  anywhere             anywhere             /* !fw3 */

  106. Chain zone_wan_output (1 references)
  107. target     prot opt source               destination
  108. output_wan_rule  all  --  anywhere             anywhere             /* !fw3: Custom wan output rule chain */
  109. zone_wan_dest_ACCEPT  all  --  anywhere             anywhere             /* !fw3 */

  110. Chain zone_wan_src_REJECT (1 references)
  111. target     prot opt source               destination
  112. reject     all  --  anywhere             anywhere             /* !fw3 */
複製代碼

TOP

在/etc/config/firewall加入以下幾行就可以
config rule
        option target 'ACCEPT'
        option src 'wan'
        option proto 'tcp'
        option dest_port '22'
        option name 'ssh'

唔需要"option dest_ip '192.168.1.1"呢行

TOP

本帖最後由 fatman 於 2019-12-14 23:44 編輯
在/etc/config/firewall加入以下幾行就可以
config rule
        option target 'ACCEPT'
        option s ...
321 發表於 2019-12-14 23:36

Ching, 試過都係一樣,都係connection refused
用forward port 就可以!

TOP

openwrt default應該唔俾從wan interface入ssh,要自行修改dropbear嘅config:
https://openwrt.org/docs/guide-user/base-system/dropbear

TOP

有d危, 基本上唔會開俾wan access
你想achieve 到d乜?

Secure your router's access
https://openwrt.org/docs/guide-user/security/secure.access

Also, as long as an attacker has network access to the console, he can always run a brute-force attack to find out username and password. He does not have to do that himself: he can let his computer(s) do the guessing. To render this option improbable or even impossible you can:

    not offer access from the Internet at all, or restrict it to certain IP addresses or IP address ranges
        by letting the SSH server dropbear and the web-Server uhttpd not listen on the external/WAN port
        by blocking incoming connections to those ports (TCP 22, 80 and 443 by default) in your firewall

TOP

ssh 係個測試,因為想開一個wan port 1234然後forward 去 LAN 其中一部機嘅ssh server.

如果用port forward rules, 係無問題。但如果用Traffic Rules 做,就做唔到。
所以想問下Traffic Rules 係唔係有特別用途?!

via HKEPC IR Pro 3.6.1 - iOS(3.0.0)

TOP

回覆 1# fatman


  我無用開openwrt... 但
發現呢句可能有問題:

config redirect               
        option target 'DNAT'         
        option src 'wan'      
        option dest 'lan'
        option proto 'tcp'        
        option src_dport '22'      <-------- 你開個 ssh client , connect 去 ssh 既 source port 唔會有指定port number , 所以試下刪左呢句先
         option dest_ip '192.168.1.1'
        option dest_port '22'         
        option name 'wan-ssh'

TOP