iptables.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. *****************
  2. Iptables
  3. *****************
  4. Iptables are used in the Debian install script.
  5. Basic Rules
  6. ^^^^^^^^^^^^
  7. | ``iptables -A INPUT -i lo -j ACCEPT``
  8. | ``iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT``
  9. | ``iptables -A INPUT -p tcp --dport 22 -j ACCEPT``
  10. | ``iptables -A INPUT -p tcp --dport 80 -j ACCEPT``
  11. | ``iptables -A INPUT -p tcp --dport 443 -j ACCEPT``
  12. | ``iptables -A INPUT -p tcp --dport 5060:5069 -j ACCEPT``
  13. | ``iptables -A INPUT -p udp --dport 5060:5069 -j ACCEPT``
  14. | ``iptables -A INPUT -p tcp --dport 5080 -j ACCEPT``
  15. | ``iptables -A INPUT -p udp --dport 5080 -j ACCEPT``
  16. | ``iptables -A INPUT -p udp --dport 16384:32768 -j ACCEPT``
  17. | ``iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT``
  18. | ``iptables -A INPUT -p udp --dport 1194 -j ACCEPT``
  19. | ``iptables -P INPUT DROP``
  20. | ``iptables -P FORWARD DROP``
  21. | ``iptables -P OUTPUT ACCEPT``
  22. Optional Rules
  23. ^^^^^^^^^^^^^^^^
  24. | OPENVPN: ``iptables -A INPUT -p udp --dport 1194 -j ACCEPT``
  25. | ICMP: ``iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT``
  26. Friendly Scanner
  27. ^^^^^^^^^^^^^^^^^^
  28. Rules to block not so friendly scanner
  29. | ``iptables -I INPUT -j DROP -p tcp --dport 5060 -m string --string "friendly-scanner" --algo bm``
  30. | ``iptables -I INPUT -j DROP -p tcp --dport 5080 -m string --string "friendly-scanner" --algo bm``
  31. | ``iptables -I INPUT -j DROP -p udp --dport 5060 -m string --string "friendly-scanner" --algo bm``
  32. | ``iptables -I INPUT -j DROP -p udp --dport 5080 -m string --string "friendly-scanner" --algo bm``
  33. | *Optional*
  34. | ``iptables -I INPUT -j DROP -p tcp --dport 5060 -m string --string "VaxSIPUserAgent" --algo bm``
  35. | ``iptables -I INPUT -j DROP -p udp --dport 5060 -m string --string "VaxIPUserAgent" --algo bm``
  36. | ``iptables -I INPUT -j DROP -p udp --dport 5080 -m string --string "VaxSIPUserAgent" --algo bm``
  37. | ``iptables -I INPUT -j DROP -p tcp --dport 5080 -m string --string "VaxIPUserAgent" --algo bm``
  38. | ``iptables -I INPUT -j DROP -p tcp --dport 5060 -m string --string "VaxSIPUserAgent/3.1" --algo bm``
  39. | ``iptables -I INPUT -j DROP -p udp --dport 5060 -m string --string "VaxSIPUserAgent/3.1" --algo bm``
  40. | ``iptables -I INPUT -j DROP -p udp --dport 5080 -m string --string "VaxSIPUserAgent/3.1" --algo bm``
  41. | ``iptables -I INPUT -j DROP -p tcp --dport 5080 -m string --string "VaxSIPUserAgent/3.1" --algo bm``
  42. Add DSCP rules
  43. ^^^^^^^^^^^^^^
  44. iptables -t mangle -A OUTPUT -p udp -m udp --sport 16384:32768 -j DSCP --set-dscp 46
  45. iptables -t mangle -A OUTPUT -p udp -m udp --sport 5060:5091 -j DSCP --set-dscp 26
  46. iptables -t mangle -A OUTPUT -p tcp -m tcp --sport 5060:5091 -j DSCP --set-dscp 26
  47. Show iptable rules
  48. ^^^^^^^^^^^^^^^^^^^
  49. ``sudo iptables -L -v``
  50. Show line numbers
  51. ^^^^^^^^^^^^^^^^^^
  52. ``iptables -L -v -n --line-numbers``
  53. Show DSCP rules
  54. ^^^^^^^^^^^^^^^
  55. iptables -vL -t mangle
  56. Delete a line
  57. ^^^^^^^^^^^^^^
  58. Delete line 2
  59. ``iptables -D INPUT 2``
  60. Flush Out Iptables
  61. ^^^^^^^^^^^^^^^^^^^
  62. | ``iptables -P INPUT ACCEPT``
  63. | ``iptables -P FORWARD ACCEPT``
  64. | ``iptables -P OUTPUT ACCEPT``
  65. | ``iptables -F``
  66. Open a Port for a Specific IP Address
  67. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  68. | ``iptables -A INPUT -j ACCEPT -p tcp --dport 5432 -s x.x.x.x/32``
  69. Block IP address
  70. ^^^^^^^^^^^^^^^^^
  71. | ``iptables -I INPUT -s 62.210.245.132 -j DROP``
  72. Restore Rules from rules.v4
  73. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  74. This reads the file rules.v4 and saved iptables rules back into active memory.
  75. | ``iptables-restore < /etc/iptables/rules.v4``
  76. Flush iptables
  77. ^^^^^^^^^^^^^^^^^
  78. How to flush iptables without loosing access to ssh.
  79. | ``iptables -P INPUT ACCEPT``
  80. | ``iptables -F``
  81. Save Changes
  82. ^^^^^^^^^^^^^
  83. Debian / Ubuntu
  84. | ``apt-get install iptables-persistent``
  85. | ``service iptables-persistent save``
  86. | ``dpkg-reconfigure iptables-persistent``
  87. | ``iptables-save > /etc/iptables/rules.v4``
  88. | ``ip6tables-save > /etc/iptables/rules.v6``