Автор Тема: не съм сигурен, че защитната ми стена работи правилно  (Прочетена 1477 пъти)

vstoykov

  • Напреднали
  • *****
  • Публикации: 1286
  • Distribution: Ubuntu
  • Window Manager: Fluxbox
    • Профил
    • WWW
Използвах http://easyfwgen.morizot.net/ за да си направя скрипт за защитна стена. Обаче се оказа, че има проблем с VPN-а, който тествах (тестов акаунт на http://www.swissvpn.net/). Редактирах скрипта, но не съм сигурен дали правилно съм го направил, защото не разбирам iptables.

Имам две машини. Първата е свързана с Интернет през eth1, а чрез eth0 (192.168.0.1) е свързана към втората (192.168.0.2). Скрипта се стартира на първата машина (на втората не и трябва предполагам).

При стартиране на VPN-а се появява ppp0.

Скрипта преди редакцията (както е генериран от easyfwgen):


Код
GeSHi (Bash):
  1. #!/bin/sh
  2. #
  3. # Generated iptables firewall script for the Linux 2.4 kernel
  4. # Script generated by Easy Firewall Generator for IPTables 1.15
  5. # copyright 2002 Timothy Scott Morizot
  6. #
  7. # Redhat chkconfig comments - firewall applied early,
  8. #                             removed late
  9. # chkconfig: 2345 08 92
  10. # description: This script applies or removes iptables firewall rules
  11. #
  12. # This generator is primarily designed for RedHat installations,
  13. # although it should be adaptable for others.
  14. #
  15. # It can be executed with the typical start and stop arguments.
  16. # If used with stop, it will stop after flushing the firewall.
  17. # The save and restore arguments will save or restore the rules
  18. # from the /etc/sysconfig/iptables file.  The save and restore
  19. # arguments are included to preserve compatibility with
  20. # Redhat's or Fedora's init.d script if you prefer to use it.
  21.  
  22. # Redhat/Fedora installation instructions
  23. #
  24. # 1. Have the system link the iptables init.d startup script into run states
  25. #    2, 3, and 5.
  26. #    chkconfig --level 235 iptables on
  27. #
  28. # 2. Save this script and execute it to load the ruleset from this file.
  29. #    You may need to run the dos2unix command on it to remove carraige returns.
  30. #
  31. # 3. To have it applied at startup, copy this script to
  32. #    /etc/init.d/iptables.  It accepts stop, start, save, and restore
  33. #    arguments.  (You may wish to save the existing one first.)
  34. #    Alternatively, if you issue the 'service iptables save' command
  35. #    the init.d script should save the rules and reload them at runtime.
  36. #
  37. # 4. For non-Redhat systems (or Redhat systems if you have a problem), you
  38. #    may want to append the command to execute this script to rc.local.
  39. #    rc.local is typically located in /etc and /etc/rc.d and is usually
  40. #    the last thing executed on startup.  Simply add /path/to/script/script_name
  41. #    on its own line in the rc.local file.
  42.  
  43. ###############################################################################
  44. #
  45. # Local Settings
  46. #
  47.  
  48. # sysctl location.  If set, it will use sysctl to adjust the kernel parameters.
  49. # If this is set to the empty string (or is unset), the use of sysctl
  50. # is disabled.
  51.  
  52. SYSCTL="/sbin/sysctl -w"
  53.  
  54. # To echo the value directly to the /proc file instead
  55. # SYSCTL=""
  56.  
  57. # IPTables Location - adjust if needed
  58.  
  59. IPT="/usr/sbin/iptables"
  60. IPTS="/usr/sbin/iptables-save"
  61. IPTR="/usr/sbin/iptables-restore"
  62.  
  63. # Internet Interface
  64. INET_IFACE="ppp0"
  65.  
  66. # Local Interface Information
  67. LOCAL_IFACE="eth0"
  68. LOCAL_IP="192.168.0.1"
  69. LOCAL_NET="192.168.0.0/24"
  70. LOCAL_BCAST="192.168.0.255"
  71.  
  72. # Localhost Interface
  73.  
  74. LO_IFACE="lo"
  75. LO_IP="127.0.0.1"
  76.  
  77. # Save and Restore arguments handled here
  78. if [ "$1" = "save" ]
  79. then
  80. echo -n "Saving firewall to /etc/sysconfig/iptables ... "
  81. $IPTS > /etc/sysconfig/iptables
  82. echo "done"
  83. exit 0
  84. elif [ "$1" = "restore" ]
  85. then
  86. echo -n "Restoring firewall from /etc/sysconfig/iptables ... "
  87. $IPTR < /etc/sysconfig/iptables
  88. echo "done"
  89. exit 0
  90. fi
  91.  
  92. ###############################################################################
  93. #
  94. # Load Modules
  95. #
  96.  
  97. echo "Loading kernel modules ..."
  98.  
  99. # You should uncomment the line below and run it the first time just to
  100. # ensure all kernel module dependencies are OK.  There is no need to run
  101. # every time, however.
  102.  
  103. # /sbin/depmod -a
  104.  
  105. # Unless you have kernel module auto-loading disabled, you should not
  106. # need to manually load each of these modules.  Other than ip_tables,
  107. # ip_conntrack, and some of the optional modules, I've left these
  108. # commented by default.  Uncomment if you have any problems or if
  109. # you have disabled module autoload.  Note that some modules must
  110. # be loaded by another kernel module.
  111.  
  112. # core netfilter module
  113. /sbin/modprobe ip_tables
  114.  
  115. # the stateful connection tracking module
  116. /sbin/modprobe ip_conntrack
  117.  
  118. # filter table module
  119. # /sbin/modprobe iptable_filter
  120.  
  121. # mangle table module
  122. # /sbin/modprobe iptable_mangle
  123.  
  124. # nat table module
  125. # /sbin/modprobe iptable_nat
  126.  
  127. # LOG target module
  128. # /sbin/modprobe ipt_LOG
  129.  
  130. # This is used to limit the number of packets per sec/min/hr
  131. # /sbin/modprobe ipt_limit
  132.  
  133. # masquerade target module
  134. # /sbin/modprobe ipt_MASQUERADE
  135.  
  136. # filter using owner as part of the match
  137. # /sbin/modprobe ipt_owner
  138.  
  139. # REJECT target drops the packet and returns an ICMP response.
  140. # The response is configurable.  By default, connection refused.
  141. # /sbin/modprobe ipt_REJECT
  142.  
  143. # This target allows packets to be marked in the mangle table
  144. # /sbin/modprobe ipt_mark
  145.  
  146. # This target affects the TCP MSS
  147. # /sbin/modprobe ipt_tcpmss
  148.  
  149. # This match allows multiple ports instead of a single port or range
  150. # /sbin/modprobe multiport
  151.  
  152. # This match checks against the TCP flags
  153. # /sbin/modprobe ipt_state
  154.  
  155. # This match catches packets with invalid flags
  156. # /sbin/modprobe ipt_unclean
  157.  
  158. # The ftp nat module is required for non-PASV ftp support
  159. /sbin/modprobe ip_nat_ftp
  160.  
  161. # the module for full ftp connection tracking
  162. /sbin/modprobe ip_conntrack_ftp
  163.  
  164. # the module for full irc connection tracking
  165. /sbin/modprobe ip_conntrack_irc
  166.  
  167.  
  168. ###############################################################################
  169. #
  170. # Kernel Parameter Configuration
  171. #
  172. # See http://ipsysctl-tutorial.frozentux.net/chunkyhtml/index.html
  173. # for a detailed tutorial on sysctl and the various settings
  174. # available.
  175.  
  176. # Required to enable IPv4 forwarding.
  177. # Redhat users can try setting FORWARD_IPV4 in /etc/sysconfig/network to true
  178. # Alternatively, it can be set in /etc/sysctl.conf
  179. if [ "$SYSCTL" = "" ]
  180. then
  181.    echo "1" > /proc/sys/net/ipv4/ip_forward
  182. else
  183.    $SYSCTL net.ipv4.ip_forward="1"
  184. fi
  185.  
  186. # This enables dynamic address hacking.
  187. # This may help if you have a dynamic IP address \(e.g. slip, ppp, dhcp\).
  188. #if [ "$SYSCTL" = "" ]
  189. #then
  190. #    echo "1" > /proc/sys/net/ipv4/ip_dynaddr
  191. #else
  192. #    $SYSCTL net.ipv4.ip_dynaddr="1"
  193. #fi
  194.  
  195. # This enables SYN flood protection.
  196. # The SYN cookies activation allows your system to accept an unlimited
  197. # number of TCP connections while still trying to give reasonable
  198. # service during a denial of service attack.
  199. if [ "$SYSCTL" = "" ]
  200. then
  201.    echo "1" > /proc/sys/net/ipv4/tcp_syncookies
  202. else
  203.    $SYSCTL net.ipv4.tcp_syncookies="1"
  204. fi
  205.  
  206. # This enables source validation by reversed path according to RFC1812.
  207. # In other words, did the response packet originate from the same interface
  208. # through which the source packet was sent?  It's recommended for single-homed
  209. # systems and routers on stub networks.  Since those are the configurations
  210. # this firewall is designed to support, I turn it on by default.
  211. # Turn it off if you use multiple NICs connected to the same network.
  212. if [ "$SYSCTL" = "" ]
  213. then
  214.    echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
  215. else
  216.    $SYSCTL net.ipv4.conf.all.rp_filter="1"
  217. fi
  218.  
  219. # This option allows a subnet to be firewalled with a single IP address.
  220. # It's used to build a DMZ.  Since that's not a focus of this firewall
  221. # script, it's not enabled by default, but is included for reference.
  222. # See: http://www.sjdjweis.com/linux/proxyarp/
  223. #if [ "$SYSCTL" = "" ]
  224. #then
  225. #    echo "1" > /proc/sys/net/ipv4/conf/all/proxy_arp
  226. #else
  227. #    $SYSCTL net.ipv4.conf.all.proxy_arp="1"
  228. #fi
  229.  
  230. # The following kernel settings were suggested by Alex Weeks. Thanks!
  231.  
  232. # This kernel parameter instructs the kernel to ignore all ICMP
  233. # echo requests sent to the broadcast address.  This prevents
  234. # a number of smurfs and similar DoS nasty attacks.
  235. if [ "$SYSCTL" = "" ]
  236. then
  237.    echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
  238. else
  239.    $SYSCTL net.ipv4.icmp_echo_ignore_broadcasts="1"
  240. fi
  241.  
  242. # This option can be used to accept or refuse source routed
  243. # packets.  It is usually on by default, but is generally
  244. # considered a security risk.  This option turns it off.
  245. if [ "$SYSCTL" = "" ]
  246. then
  247.    echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
  248. else
  249.    $SYSCTL net.ipv4.conf.all.accept_source_route="0"
  250. fi
  251.  
  252. # This option can disable ICMP redirects.  ICMP redirects
  253. # are generally considered a security risk and shouldn't be
  254. # needed by most systems using this generator.
  255. #if [ "$SYSCTL" = "" ]
  256. #then
  257. #    echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
  258. #else
  259. #    $SYSCTL net.ipv4.conf.all.accept_redirects="0"
  260. #fi
  261.  
  262. # However, we'll ensure the secure_redirects option is on instead.
  263. # This option accepts only from gateways in the default gateways list.
  264. if [ "$SYSCTL" = "" ]
  265. then
  266.    echo "1" > /proc/sys/net/ipv4/conf/all/secure_redirects
  267. else
  268.    $SYSCTL net.ipv4.conf.all.secure_redirects="1"
  269. fi
  270.  
  271. # This option logs packets from impossible addresses.
  272. if [ "$SYSCTL" = "" ]
  273. then
  274.    echo "1" > /proc/sys/net/ipv4/conf/all/log_martians
  275. else
  276.    $SYSCTL net.ipv4.conf.all.log_martians="1"
  277. fi
  278.  
  279.  
  280. ###############################################################################
  281. #
  282. # Flush Any Existing Rules or Chains
  283. #
  284.  
  285. echo "Flushing Tables ..."
  286.  
  287. # Reset Default Policies
  288. $IPT -P INPUT ACCEPT
  289. $IPT -P FORWARD ACCEPT
  290. $IPT -P OUTPUT ACCEPT
  291. $IPT -t nat -P PREROUTING ACCEPT
  292. $IPT -t nat -P POSTROUTING ACCEPT
  293. $IPT -t nat -P OUTPUT ACCEPT
  294. $IPT -t mangle -P PREROUTING ACCEPT
  295. $IPT -t mangle -P OUTPUT ACCEPT
  296.  
  297. # Flush all rules
  298. $IPT -F
  299. $IPT -t nat -F
  300. $IPT -t mangle -F
  301.  
  302. # Erase all non-default chains
  303. $IPT -X
  304. $IPT -t nat -X
  305. $IPT -t mangle -X
  306.  
  307. if [ "$1" = "stop" ]
  308. then
  309. echo "Firewall completely flushed!  Now running with no firewall."
  310. exit 0
  311. fi
  312.  
  313. ###############################################################################
  314. #
  315. # Rules Configuration
  316. #
  317.  
  318. ###############################################################################
  319. #
  320. # Filter Table
  321. #
  322. ###############################################################################
  323.  
  324. # Set Policies
  325.  
  326. $IPT -P INPUT DROP
  327. $IPT -P OUTPUT DROP
  328. $IPT -P FORWARD DROP
  329.  
  330. ###############################################################################
  331. #
  332. # User-Specified Chains
  333. #
  334. # Create user chains to reduce the number of rules each packet
  335. # must traverse.
  336.  
  337. echo "Create and populate custom rule chains ..."
  338.  
  339. # Create a chain to filter INVALID packets
  340.  
  341. $IPT -N bad_packets
  342.  
  343. # Create another chain to filter bad tcp packets
  344.  
  345. $IPT -N bad_tcp_packets
  346.  
  347. # Create separate chains for icmp, tcp (incoming and outgoing),
  348. # and incoming udp packets.
  349.  
  350. $IPT -N icmp_packets
  351.  
  352. # Used for UDP packets inbound from the Internet
  353. $IPT -N udp_inbound
  354.  
  355. # Used to block outbound UDP services from internal network
  356. # Default to allow all
  357. $IPT -N udp_outbound
  358.  
  359. # Used to allow inbound services if desired
  360. # Default fail except for established sessions
  361. $IPT -N tcp_inbound
  362.  
  363. # Used to block outbound services from internal network
  364. # Default to allow all
  365. $IPT -N tcp_outbound
  366.  
  367. ###############################################################################
  368. #
  369. # Populate User Chains
  370. #
  371.  
  372. # bad_packets chain
  373. #
  374.  
  375. # Drop packets received on the external interface
  376. # claiming a source of the local network
  377. $IPT -A bad_packets -p ALL -i $INET_IFACE -s $LOCAL_NET -j LOG \
  378.    --log-prefix "Illegal source: "
  379.  
  380. $IPT -A bad_packets -p ALL -i $INET_IFACE -s $LOCAL_NET -j DROP
  381.  
  382. # Drop INVALID packets immediately
  383. $IPT -A bad_packets -p ALL -m state --state INVALID -j LOG \
  384.    --log-prefix "Invalid packet: "
  385.  
  386. $IPT -A bad_packets -p ALL -m state --state INVALID -j DROP
  387.  
  388. # Then check the tcp packets for additional problems
  389. $IPT -A bad_packets -p tcp -j bad_tcp_packets
  390.  
  391. # All good, so return
  392. $IPT -A bad_packets -p ALL -j RETURN
  393.  
  394. # bad_tcp_packets chain
  395. #
  396. # All tcp packets will traverse this chain.
  397. # Every new connection attempt should begin with
  398. # a syn packet.  If it doesn't, it is likely a
  399. # port scan.  This drops packets in state
  400. # NEW that are not flagged as syn packets.
  401.  
  402. # Return to the calling chain if the bad packets originate
  403. # from the local interface. This maintains the approach
  404. # throughout this firewall of a largely trusted internal
  405. # network.
  406. $IPT -A bad_tcp_packets -p tcp -i $LOCAL_IFACE -j RETURN
  407.  
  408. # However, I originally did apply this filter to the forward chain
  409. # for packets originating from the internal network.  While I have
  410. # not conclusively determined its effect, it appears to have the
  411. # interesting side effect of blocking some of the ad systems.
  412. # Apparently some ad systems have the browser initiate a NEW
  413. # connection that is not flagged as a syn packet to retrieve
  414. # the ad image.  If you wish to experiment further comment the
  415. # rule above. If you try it, you may also wish to uncomment the
  416. # rule below.  It will keep those packets from being logged.
  417. # There are a lot of them.
  418. # $IPT -A bad_tcp_packets -p tcp -i $LOCAL_IFACE ! --syn -m state \
  419. #     --state NEW -j DROP
  420.  
  421. $IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG \
  422.    --log-prefix "New not syn: "
  423. $IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
  424.  
  425. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL NONE -j LOG \
  426.    --log-prefix "Stealth scan: "
  427. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL NONE -j DROP
  428.  
  429. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL ALL -j LOG \
  430.    --log-prefix "Stealth scan: "
  431. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL ALL -j DROP
  432.  
  433. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL FIN,URG,PSH -j LOG \
  434.    --log-prefix "Stealth scan: "
  435. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
  436.  
  437. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j LOG \
  438.    --log-prefix "Stealth scan: "
  439. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  440.  
  441. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,RST SYN,RST -j LOG \
  442.    --log-prefix "Stealth scan: "
  443. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
  444.  
  445. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,FIN SYN,FIN -j LOG \
  446.    --log-prefix "Stealth scan: "
  447. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
  448.  
  449. # All good, so return
  450. $IPT -A bad_tcp_packets -p tcp -j RETURN
  451.  
  452. # icmp_packets chain
  453. #
  454. # This chain is for inbound (from the Internet) icmp packets only.
  455. # Type 8 (Echo Request) is not accepted by default
  456. # Enable it if you want remote hosts to be able to reach you.
  457. # 11 (Time Exceeded) is the only one accepted
  458. # that would not already be covered by the established
  459. # connection rule.  Applied to INPUT on the external interface.
  460. #
  461. # See: http://www.ee.siue.edu/~rwalden/networking/icmp.html
  462. # for more info on ICMP types.
  463. #
  464. # Note that the stateful settings allow replies to ICMP packets.
  465. # These rules allow new packets of the specified types.
  466.  
  467. # ICMP packets should fit in a Layer 2 frame, thus they should
  468. # never be fragmented.  Fragmented ICMP packets are a typical sign
  469. # of a denial of service attack.
  470. $IPT -A icmp_packets --fragment -p ICMP -j LOG \
  471.    --log-prefix "ICMP Fragment: "
  472. $IPT -A icmp_packets --fragment -p ICMP -j DROP
  473.  
  474. # Echo - uncomment to allow your system to be pinged.
  475. # Uncomment the LOG command if you also want to log PING attempts
  476. #
  477. # $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j LOG \
  478. #    --log-prefix "Ping detected: "
  479. # $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
  480.  
  481. # By default, however, drop pings without logging. Blaster
  482. # and other worms have infected systems blasting pings.
  483. # Comment the line below if you want pings logged, but it
  484. # will likely fill your logs.
  485. $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j DROP
  486.  
  487. # Time Exceeded
  488. $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT
  489.  
  490. # Not matched, so return so it will be logged
  491. $IPT -A icmp_packets -p ICMP -j RETURN
  492.  
  493. # TCP & UDP
  494. # Identify ports at:
  495. #    http://www.chebucto.ns.ca/~rakerman/port-table.html
  496. #    http://www.iana.org/assignments/port-numbers
  497.  
  498. # udp_inbound chain
  499. #
  500. # This chain describes the inbound UDP packets it will accept.
  501. # It's applied to INPUT on the external or Internet interface.
  502. # Note that the stateful settings allow replies.
  503. # These rules are for new requests.
  504. # It drops netbios packets (windows) immediately without logging.
  505.  
  506. # Drop netbios calls
  507. # Please note that these rules do not really change the way the firewall
  508. # treats netbios connections.  Connections from the localhost and
  509. # internal interface (if one exists) are accepted by default.
  510. # Responses from the Internet to requests initiated by or through
  511. # the firewall are also accepted by default.  To get here, the
  512. # packets would have to be part of a new request received by the
  513. # Internet interface.  You would have to manually add rules to
  514. # accept these.  I added these rules because some network connections,
  515. # such as those via cable modems, tend to be filled with noise from
  516. # unprotected Windows machines.  These rules drop those packets
  517. # quickly and without logging them.  This prevents them from traversing
  518. # the whole chain and keeps the log from getting cluttered with
  519. # chatter from Windows systems.
  520. $IPT -A udp_inbound -p UDP -s 0/0 --destination-port 137 -j DROP
  521. $IPT -A udp_inbound -p UDP -s 0/0 --destination-port 138 -j DROP
  522.  
  523. # Dynamic Address
  524. # If DHCP, the initial request is a broadcast. The response
  525. # doesn't exactly match the outbound packet.  This explicitly
  526. # allow the DHCP ports to alleviate this problem.
  527. # If you receive your dynamic address by a different means, you
  528. # can probably comment this line.
  529. $IPT -A udp_inbound -p UDP -s 0/0 --source-port 67 --destination-port 68 \
  530.     -j ACCEPT
  531.  
  532.  
  533. # Not matched, so return for logging
  534. $IPT -A udp_inbound -p UDP -j RETURN
  535.  
  536. # udp_outbound chain
  537. #
  538. # This chain is used with a private network to prevent forwarding for
  539. # UDP requests on specific protocols.  Applied to the FORWARD rule from
  540. # the internal network.  Ends with an ACCEPT
  541.  
  542.  
  543. # No match, so ACCEPT
  544. $IPT -A udp_outbound -p UDP -s 0/0 -j ACCEPT
  545.  
  546. # tcp_inbound chain
  547. #
  548. # This chain is used to allow inbound connections to the
  549. # system/gateway.  Use with care.  It defaults to none.
  550. # It's applied on INPUT from the external or Internet interface.
  551.  
  552.  
  553. # Not matched, so return so it will be logged
  554. $IPT -A tcp_inbound -p TCP -j RETURN
  555.  
  556. # tcp_outbound chain
  557. #
  558. # This chain is used with a private network to prevent forwarding for
  559. # requests on specific protocols.  Applied to the FORWARD rule from
  560. # the internal network.  Ends with an ACCEPT
  561.  
  562.  
  563. # No match, so ACCEPT
  564. $IPT -A tcp_outbound -p TCP -s 0/0 -j ACCEPT
  565.  
  566. ###############################################################################
  567. #
  568. # INPUT Chain
  569. #
  570.  
  571. echo "Process INPUT chain ..."
  572.  
  573. # Allow all on localhost interface
  574. $IPT -A INPUT -p ALL -i $LO_IFACE -j ACCEPT
  575.  
  576. # Drop bad packets
  577. $IPT -A INPUT -p ALL -j bad_packets
  578.  
  579. # DOCSIS compliant cable modems
  580. # Some DOCSIS compliant cable modems send IGMP multicasts to find
  581. # connected PCs.  The multicast packets have the destination address
  582. # 224.0.0.1.  You can accept them.  If you choose to do so,
  583. # Uncomment the rule to ACCEPT them and comment the rule to DROP
  584. # them  The firewall will drop them here by default to avoid
  585. # cluttering the log.  The firewall will drop all multicasts
  586. # to the entire subnet (224.0.0.1) by default.  To only affect
  587. # IGMP multicasts, change '-p ALL' to '-p 2'.  Of course,
  588. # if they aren't accepted elsewhere, it will only ensure that
  589. # multicasts on other protocols are logged.
  590. # Drop them without logging.
  591. $IPT -A INPUT -p ALL -d 224.0.0.1 -j DROP
  592. # The rule to accept the packets.
  593. # $IPT -A INPUT -p ALL -d 224.0.0.1 -j ACCEPT
  594.  
  595. # Rules for the private network (accessing gateway system itself)
  596. $IPT -A INPUT -p ALL -i $LOCAL_IFACE -s $LOCAL_NET -j ACCEPT
  597. $IPT -A INPUT -p ALL -i $LOCAL_IFACE -d $LOCAL_BCAST -j ACCEPT
  598.  
  599.  
  600. # Inbound Internet Packet Rules
  601.  
  602. # Accept Established Connections
  603. $IPT -A INPUT -p ALL -i $INET_IFACE -m state --state ESTABLISHED,RELATED \
  604.     -j ACCEPT
  605.  
  606. # Route the rest to the appropriate user chain
  607. $IPT -A INPUT -p TCP -i $INET_IFACE -j tcp_inbound
  608. $IPT -A INPUT -p UDP -i $INET_IFACE -j udp_inbound
  609. $IPT -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
  610.  
  611. # Drop without logging broadcasts that get this far.
  612. # Cuts down on log clutter.
  613. # Comment this line if testing new rules that impact
  614. # broadcast protocols.
  615. $IPT -A INPUT -m pkttype --pkt-type broadcast -j DROP
  616.  
  617. # Log packets that still don't match
  618. $IPT -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
  619.    --log-prefix "INPUT packet died: "
  620.  
  621. ###############################################################################
  622. #
  623. # FORWARD Chain
  624. #
  625.  
  626. echo "Process FORWARD chain ..."
  627.  
  628. # Used if forwarding for a private network
  629.  
  630. # Drop bad packets
  631. $IPT -A FORWARD -p ALL -j bad_packets
  632.  
  633. # Accept TCP packets we want to forward from internal sources
  634. $IPT -A FORWARD -p tcp -i $LOCAL_IFACE -j tcp_outbound
  635.  
  636. # Accept UDP packets we want to forward from internal sources
  637. $IPT -A FORWARD -p udp -i $LOCAL_IFACE -j udp_outbound
  638.  
  639. # If not blocked, accept any other packets from the internal interface
  640. $IPT -A FORWARD -p ALL -i $LOCAL_IFACE -j ACCEPT
  641.  
  642. # Deal with responses from the internet
  643. $IPT -A FORWARD -i $INET_IFACE -m state --state ESTABLISHED,RELATED \
  644.     -j ACCEPT
  645.  
  646. # Log packets that still don't match
  647. $IPT -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG \
  648.    --log-prefix "FORWARD packet died: "
  649.  
  650. ###############################################################################
  651. #
  652. # OUTPUT Chain
  653. #
  654.  
  655. echo "Process OUTPUT chain ..."
  656.  
  657. # Generally trust the firewall on output
  658.  
  659. # However, invalid icmp packets need to be dropped
  660. # to prevent a possible exploit.
  661. $IPT -A OUTPUT -m state -p icmp --state INVALID -j DROP
  662.  
  663. # Localhost
  664. $IPT -A OUTPUT -p ALL -s $LO_IP -j ACCEPT
  665. $IPT -A OUTPUT -p ALL -o $LO_IFACE -j ACCEPT
  666.  
  667. # To internal network
  668. $IPT -A OUTPUT -p ALL -s $LOCAL_IP -j ACCEPT
  669. $IPT -A OUTPUT -p ALL -o $LOCAL_IFACE -j ACCEPT
  670.  
  671. # To internet
  672. $IPT -A OUTPUT -p ALL -o $INET_IFACE -j ACCEPT
  673.  
  674. # Log packets that still don't match
  675. $IPT -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
  676.    --log-prefix "OUTPUT packet died: "
  677.  
  678. ###############################################################################
  679. #
  680. # nat table
  681. #
  682. ###############################################################################
  683.  
  684. # The nat table is where network address translation occurs if there
  685. # is a private network.  If the gateway is connected to the Internet
  686. # with a static IP, snat is used.  If the gateway has a dynamic address,
  687. # masquerade must be used instead.  There is more overhead associated
  688. # with masquerade, so snat is better when it can be used.
  689. # The nat table has a builtin chain, PREROUTING, for dnat and redirects.
  690. # Another, POSTROUTING, handles snat and masquerade.
  691.  
  692. echo "Load rules for nat table ..."
  693.  
  694. ###############################################################################
  695. #
  696. # PREROUTING chain
  697. #
  698.  
  699.  
  700. ###############################################################################
  701. #
  702. # POSTROUTING chain
  703. #
  704.  
  705. $IPT -t nat -A POSTROUTING -o $INET_IFACE -j MASQUERADE
  706.  
  707. ###############################################################################
  708. #
  709. # mangle table
  710. #
  711. ###############################################################################
  712.  
  713. # The mangle table is used to alter packets.  It can alter or mangle them in
  714. # several ways.  For the purposes of this generator, we only use its ability
  715. # to alter the TTL in packets.  However, it can be used to set netfilter
  716. # mark values on specific packets.  Those marks could then be used in another
  717. # table like filter, to limit activities associated with a specific host, for
  718. # instance.  The TOS target can be used to set the Type of Service field in
  719. # the IP header.  Note that the TTL target might not be included in the
  720. # distribution on your system.  If it is not and you require it, you will
  721. # have to add it.  That may require that you build from source.
  722.  
  723. echo "Load rules for mangle table ..."
  724.  
  725.  

След редакцията:
Код
GeSHi (Bash):
  1. #!/bin/sh
  2. #
  3. # Generated iptables firewall script for the Linux 2.4 kernel
  4. # Script generated by Easy Firewall Generator for IPTables 1.15
  5. # copyright 2002 Timothy Scott Morizot
  6. #
  7. # Redhat chkconfig comments - firewall applied early,
  8. #                             removed late
  9. # chkconfig: 2345 08 92
  10. # description: This script applies or removes iptables firewall rules
  11. #
  12. # This generator is primarily designed for RedHat installations,
  13. # although it should be adaptable for others.
  14. #
  15. # It can be executed with the typical start and stop arguments.
  16. # If used with stop, it will stop after flushing the firewall.
  17. # The save and restore arguments will save or restore the rules
  18. # from the /etc/sysconfig/iptables file.  The save and restore
  19. # arguments are included to preserve compatibility with
  20. # Redhat's or Fedora's init.d script if you prefer to use it.
  21.  
  22. # Redhat/Fedora installation instructions
  23. #
  24. # 1. Have the system link the iptables init.d startup script into run states
  25. #    2, 3, and 5.
  26. #    chkconfig --level 235 iptables on
  27. #
  28. # 2. Save this script and execute it to load the ruleset from this file.
  29. #    You may need to run the dos2unix command on it to remove carraige returns.
  30. #
  31. # 3. To have it applied at startup, copy this script to
  32. #    /etc/init.d/iptables.  It accepts stop, start, save, and restore
  33. #    arguments.  (You may wish to save the existing one first.)
  34. #    Alternatively, if you issue the 'service iptables save' command
  35. #    the init.d script should save the rules and reload them at runtime.
  36. #
  37. # 4. For non-Redhat systems (or Redhat systems if you have a problem), you
  38. #    may want to append the command to execute this script to rc.local.
  39. #    rc.local is typically located in /etc and /etc/rc.d and is usually
  40. #    the last thing executed on startup.  Simply add /path/to/script/script_name
  41. #    on its own line in the rc.local file.
  42.  
  43. ###############################################################################
  44. #
  45. # Local Settings
  46. #
  47.  
  48. # sysctl location.  If set, it will use sysctl to adjust the kernel parameters.
  49. # If this is set to the empty string (or is unset), the use of sysctl
  50. # is disabled.
  51.  
  52. SYSCTL="/sbin/sysctl -w"
  53.  
  54. # To echo the value directly to the /proc file instead
  55. # SYSCTL=""
  56.  
  57. # IPTables Location - adjust if needed
  58.  
  59. IPT="/usr/sbin/iptables"
  60. IPTS="/usr/sbin/iptables-save"
  61. IPTR="/usr/sbin/iptables-restore"
  62.  
  63. # Internet Interface
  64. INET_IFACE="ppp0"
  65. INET_IFACE2="eth1"
  66.  
  67. # Local Interface Information
  68. LOCAL_IFACE="eth0"
  69. LOCAL_IP="192.168.0.1"
  70. LOCAL_NET="192.168.0.0/24"
  71. LOCAL_BCAST="192.168.0.255"
  72.  
  73. # Localhost Interface
  74.  
  75. LO_IFACE="lo"
  76. LO_IP="127.0.0.1"
  77.  
  78. # Save and Restore arguments handled here
  79. if [ "$1" = "save" ]
  80. then
  81. echo -n "Saving firewall to /etc/sysconfig/iptables ... "
  82. $IPTS > /etc/sysconfig/iptables
  83. echo "done"
  84. exit 0
  85. elif [ "$1" = "restore" ]
  86. then
  87. echo -n "Restoring firewall from /etc/sysconfig/iptables ... "
  88. $IPTR < /etc/sysconfig/iptables
  89. echo "done"
  90. exit 0
  91. fi
  92.  
  93. ###############################################################################
  94. #
  95. # Load Modules
  96. #
  97.  
  98. echo "Loading kernel modules ..."
  99.  
  100. # You should uncomment the line below and run it the first time just to
  101. # ensure all kernel module dependencies are OK.  There is no need to run
  102. # every time, however.
  103.  
  104. # /sbin/depmod -a
  105.  
  106. # Unless you have kernel module auto-loading disabled, you should not
  107. # need to manually load each of these modules.  Other than ip_tables,
  108. # ip_conntrack, and some of the optional modules, I've left these
  109. # commented by default.  Uncomment if you have any problems or if
  110. # you have disabled module autoload.  Note that some modules must
  111. # be loaded by another kernel module.
  112.  
  113. # core netfilter module
  114. /sbin/modprobe ip_tables
  115.  
  116. # the stateful connection tracking module
  117. /sbin/modprobe ip_conntrack
  118.  
  119. # filter table module
  120. # /sbin/modprobe iptable_filter
  121.  
  122. # mangle table module
  123. # /sbin/modprobe iptable_mangle
  124.  
  125. # nat table module
  126. # /sbin/modprobe iptable_nat
  127.  
  128. # LOG target module
  129. # /sbin/modprobe ipt_LOG
  130.  
  131. # This is used to limit the number of packets per sec/min/hr
  132. # /sbin/modprobe ipt_limit
  133.  
  134. # masquerade target module
  135. # /sbin/modprobe ipt_MASQUERADE
  136.  
  137. # filter using owner as part of the match
  138. # /sbin/modprobe ipt_owner
  139.  
  140. # REJECT target drops the packet and returns an ICMP response.
  141. # The response is configurable.  By default, connection refused.
  142. # /sbin/modprobe ipt_REJECT
  143.  
  144. # This target allows packets to be marked in the mangle table
  145. # /sbin/modprobe ipt_mark
  146.  
  147. # This target affects the TCP MSS
  148. # /sbin/modprobe ipt_tcpmss
  149.  
  150. # This match allows multiple ports instead of a single port or range
  151. # /sbin/modprobe multiport
  152.  
  153. # This match checks against the TCP flags
  154. # /sbin/modprobe ipt_state
  155.  
  156. # This match catches packets with invalid flags
  157. # /sbin/modprobe ipt_unclean
  158.  
  159. # The ftp nat module is required for non-PASV ftp support
  160. /sbin/modprobe ip_nat_ftp
  161.  
  162. # the module for full ftp connection tracking
  163. /sbin/modprobe ip_conntrack_ftp
  164.  
  165. # the module for full irc connection tracking
  166. /sbin/modprobe ip_conntrack_irc
  167.  
  168.  
  169. ###############################################################################
  170. #
  171. # Kernel Parameter Configuration
  172. #
  173. # See http://ipsysctl-tutorial.frozentux.net/chunkyhtml/index.html
  174. # for a detailed tutorial on sysctl and the various settings
  175. # available.
  176.  
  177. # Required to enable IPv4 forwarding.
  178. # Redhat users can try setting FORWARD_IPV4 in /etc/sysconfig/network to true
  179. # Alternatively, it can be set in /etc/sysctl.conf
  180. if [ "$SYSCTL" = "" ]
  181. then
  182.    echo "1" > /proc/sys/net/ipv4/ip_forward
  183. else
  184.    $SYSCTL net.ipv4.ip_forward="1"
  185. fi
  186.  
  187. # This enables dynamic address hacking.
  188. # This may help if you have a dynamic IP address \(e.g. slip, ppp, dhcp\).
  189. #if [ "$SYSCTL" = "" ]
  190. #then
  191. #    echo "1" > /proc/sys/net/ipv4/ip_dynaddr
  192. #else
  193. #    $SYSCTL net.ipv4.ip_dynaddr="1"
  194. #fi
  195.  
  196. # This enables SYN flood protection.
  197. # The SYN cookies activation allows your system to accept an unlimited
  198. # number of TCP connections while still trying to give reasonable
  199. # service during a denial of service attack.
  200. if [ "$SYSCTL" = "" ]
  201. then
  202.    echo "1" > /proc/sys/net/ipv4/tcp_syncookies
  203. else
  204.    $SYSCTL net.ipv4.tcp_syncookies="1"
  205. fi
  206.  
  207. # This enables source validation by reversed path according to RFC1812.
  208. # In other words, did the response packet originate from the same interface
  209. # through which the source packet was sent?  It's recommended for single-homed
  210. # systems and routers on stub networks.  Since those are the configurations
  211. # this firewall is designed to support, I turn it on by default.
  212. # Turn it off if you use multiple NICs connected to the same network.
  213. if [ "$SYSCTL" = "" ]
  214. then
  215.    echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
  216. else
  217.    $SYSCTL net.ipv4.conf.all.rp_filter="1"
  218. fi
  219.  
  220. # This option allows a subnet to be firewalled with a single IP address.
  221. # It's used to build a DMZ.  Since that's not a focus of this firewall
  222. # script, it's not enabled by default, but is included for reference.
  223. # See: http://www.sjdjweis.com/linux/proxyarp/
  224. #if [ "$SYSCTL" = "" ]
  225. #then
  226. #    echo "1" > /proc/sys/net/ipv4/conf/all/proxy_arp
  227. #else
  228. #    $SYSCTL net.ipv4.conf.all.proxy_arp="1"
  229. #fi
  230.  
  231. # The following kernel settings were suggested by Alex Weeks. Thanks!
  232.  
  233. # This kernel parameter instructs the kernel to ignore all ICMP
  234. # echo requests sent to the broadcast address.  This prevents
  235. # a number of smurfs and similar DoS nasty attacks.
  236. if [ "$SYSCTL" = "" ]
  237. then
  238.    echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
  239. else
  240.    $SYSCTL net.ipv4.icmp_echo_ignore_broadcasts="1"
  241. fi
  242.  
  243. # This option can be used to accept or refuse source routed
  244. # packets.  It is usually on by default, but is generally
  245. # considered a security risk.  This option turns it off.
  246. if [ "$SYSCTL" = "" ]
  247. then
  248.    echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
  249. else
  250.    $SYSCTL net.ipv4.conf.all.accept_source_route="0"
  251. fi
  252.  
  253. # This option can disable ICMP redirects.  ICMP redirects
  254. # are generally considered a security risk and shouldn't be
  255. # needed by most systems using this generator.
  256. #if [ "$SYSCTL" = "" ]
  257. #then
  258. #    echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
  259. #else
  260. #    $SYSCTL net.ipv4.conf.all.accept_redirects="0"
  261. #fi
  262.  
  263. # However, we'll ensure the secure_redirects option is on instead.
  264. # This option accepts only from gateways in the default gateways list.
  265. if [ "$SYSCTL" = "" ]
  266. then
  267.    echo "1" > /proc/sys/net/ipv4/conf/all/secure_redirects
  268. else
  269.    $SYSCTL net.ipv4.conf.all.secure_redirects="1"
  270. fi
  271.  
  272. # This option logs packets from impossible addresses.
  273. if [ "$SYSCTL" = "" ]
  274. then
  275.    echo "1" > /proc/sys/net/ipv4/conf/all/log_martians
  276. else
  277.    $SYSCTL net.ipv4.conf.all.log_martians="1"
  278. fi
  279.  
  280.  
  281. ###############################################################################
  282. #
  283. # Flush Any Existing Rules or Chains
  284. #
  285.  
  286. echo "Flushing Tables ..."
  287.  
  288. # Reset Default Policies
  289. $IPT -P INPUT ACCEPT
  290. $IPT -P FORWARD ACCEPT
  291. $IPT -P OUTPUT ACCEPT
  292. $IPT -t nat -P PREROUTING ACCEPT
  293. $IPT -t nat -P POSTROUTING ACCEPT
  294. $IPT -t nat -P OUTPUT ACCEPT
  295. $IPT -t mangle -P PREROUTING ACCEPT
  296. $IPT -t mangle -P OUTPUT ACCEPT
  297.  
  298. # Flush all rules
  299. $IPT -F
  300. $IPT -t nat -F
  301. $IPT -t mangle -F
  302.  
  303. # Erase all non-default chains
  304. $IPT -X
  305. $IPT -t nat -X
  306. $IPT -t mangle -X
  307.  
  308. if [ "$1" = "stop" ]
  309. then
  310. echo "Firewall completely flushed!  Now running with no firewall."
  311. exit 0
  312. fi
  313.  
  314. ###############################################################################
  315. #
  316. # Rules Configuration
  317. #
  318.  
  319. ###############################################################################
  320. #
  321. # Filter Table
  322. #
  323. ###############################################################################
  324.  
  325. # Set Policies
  326.  
  327. $IPT -P INPUT DROP
  328. $IPT -P OUTPUT DROP
  329. $IPT -P FORWARD DROP
  330.  
  331. ###############################################################################
  332. #
  333. # User-Specified Chains
  334. #
  335. # Create user chains to reduce the number of rules each packet
  336. # must traverse.
  337.  
  338. echo "Create and populate custom rule chains ..."
  339.  
  340. # Create a chain to filter INVALID packets
  341.  
  342. $IPT -N bad_packets
  343.  
  344. # Create another chain to filter bad tcp packets
  345.  
  346. $IPT -N bad_tcp_packets
  347.  
  348. # Create separate chains for icmp, tcp (incoming and outgoing),
  349. # and incoming udp packets.
  350.  
  351. $IPT -N icmp_packets
  352.  
  353. # Used for UDP packets inbound from the Internet
  354. $IPT -N udp_inbound
  355.  
  356. # Used to block outbound UDP services from internal network
  357. # Default to allow all
  358. $IPT -N udp_outbound
  359.  
  360. # Used to allow inbound services if desired
  361. # Default fail except for established sessions
  362. $IPT -N tcp_inbound
  363.  
  364. # Used to block outbound services from internal network
  365. # Default to allow all
  366. $IPT -N tcp_outbound
  367.  
  368. ###############################################################################
  369. #
  370. # Populate User Chains
  371. #
  372.  
  373. # bad_packets chain
  374. #
  375.  
  376. # Drop packets received on the external interface
  377. # claiming a source of the local network
  378. $IPT -A bad_packets -p ALL -i $INET_IFACE -s $LOCAL_NET -j LOG \
  379.    --log-prefix "Illegal source: "
  380.  
  381. $IPT -A bad_packets -p ALL -i $INET_IFACE2 -s $LOCAL_NET -j LOG \
  382.    --log-prefix "Illegal source: "
  383.  
  384. $IPT -A bad_packets -p ALL -i $INET_IFACE -s $LOCAL_NET -j DROP
  385.  
  386. $IPT -A bad_packets -p ALL -i $INET_IFACE2 -s $LOCAL_NET -j DROP
  387.  
  388. # Drop INVALID packets immediately
  389. $IPT -A bad_packets -p ALL -m state --state INVALID -j LOG \
  390.    --log-prefix "Invalid packet: "
  391.  
  392. $IPT -A bad_packets -p ALL -m state --state INVALID -j DROP
  393.  
  394. # Then check the tcp packets for additional problems
  395. $IPT -A bad_packets -p tcp -j bad_tcp_packets
  396.  
  397. # All good, so return
  398. $IPT -A bad_packets -p ALL -j RETURN
  399.  
  400. # bad_tcp_packets chain
  401. #
  402. # All tcp packets will traverse this chain.
  403. # Every new connection attempt should begin with
  404. # a syn packet.  If it doesn't, it is likely a
  405. # port scan.  This drops packets in state
  406. # NEW that are not flagged as syn packets.
  407.  
  408. # Return to the calling chain if the bad packets originate
  409. # from the local interface. This maintains the approach
  410. # throughout this firewall of a largely trusted internal
  411. # network.
  412. $IPT -A bad_tcp_packets -p tcp -i $LOCAL_IFACE -j RETURN
  413.  
  414. # However, I originally did apply this filter to the forward chain
  415. # for packets originating from the internal network.  While I have
  416. # not conclusively determined its effect, it appears to have the
  417. # interesting side effect of blocking some of the ad systems.
  418. # Apparently some ad systems have the browser initiate a NEW
  419. # connection that is not flagged as a syn packet to retrieve
  420. # the ad image.  If you wish to experiment further comment the
  421. # rule above. If you try it, you may also wish to uncomment the
  422. # rule below.  It will keep those packets from being logged.
  423. # There are a lot of them.
  424. # $IPT -A bad_tcp_packets -p tcp -i $LOCAL_IFACE ! --syn -m state \
  425. #     --state NEW -j DROP
  426.  
  427. $IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG \
  428.    --log-prefix "New not syn: "
  429. $IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
  430.  
  431. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL NONE -j LOG \
  432.    --log-prefix "Stealth scan: "
  433. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL NONE -j DROP
  434.  
  435. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL ALL -j LOG \
  436.    --log-prefix "Stealth scan: "
  437. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL ALL -j DROP
  438.  
  439. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL FIN,URG,PSH -j LOG \
  440.    --log-prefix "Stealth scan: "
  441. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
  442.  
  443. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j LOG \
  444.    --log-prefix "Stealth scan: "
  445. $IPT -A bad_tcp_packets -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  446.  
  447. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,RST SYN,RST -j LOG \
  448.    --log-prefix "Stealth scan: "
  449. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
  450.  
  451. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,FIN SYN,FIN -j LOG \
  452.    --log-prefix "Stealth scan: "
  453. $IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
  454.  
  455. # All good, so return
  456. $IPT -A bad_tcp_packets -p tcp -j RETURN
  457.  
  458. # icmp_packets chain
  459. #
  460. # This chain is for inbound (from the Internet) icmp packets only.
  461. # Type 8 (Echo Request) is not accepted by default
  462. # Enable it if you want remote hosts to be able to reach you.
  463. # 11 (Time Exceeded) is the only one accepted
  464. # that would not already be covered by the established
  465. # connection rule.  Applied to INPUT on the external interface.
  466. #
  467. # See: http://www.ee.siue.edu/~rwalden/networking/icmp.html
  468. # for more info on ICMP types.
  469. #
  470. # Note that the stateful settings allow replies to ICMP packets.
  471. # These rules allow new packets of the specified types.
  472.  
  473. # ICMP packets should fit in a Layer 2 frame, thus they should
  474. # never be fragmented.  Fragmented ICMP packets are a typical sign
  475. # of a denial of service attack.
  476. $IPT -A icmp_packets --fragment -p ICMP -j LOG \
  477.    --log-prefix "ICMP Fragment: "
  478. $IPT -A icmp_packets --fragment -p ICMP -j DROP
  479.  
  480. # Echo - uncomment to allow your system to be pinged.
  481. # Uncomment the LOG command if you also want to log PING attempts
  482. #
  483. # $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j LOG \
  484. #    --log-prefix "Ping detected: "
  485. # $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
  486.  
  487. # By default, however, drop pings without logging. Blaster
  488. # and other worms have infected systems blasting pings.
  489. # Comment the line below if you want pings logged, but it
  490. # will likely fill your logs.
  491. $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j DROP
  492.  
  493. # Time Exceeded
  494. $IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT
  495.  
  496. # Not matched, so return so it will be logged
  497. $IPT -A icmp_packets -p ICMP -j RETURN
  498.  
  499. # TCP & UDP
  500. # Identify ports at:
  501. #    http://www.chebucto.ns.ca/~rakerman/port-table.html
  502. #    http://www.iana.org/assignments/port-numbers
  503.  
  504. # udp_inbound chain
  505. #
  506. # This chain describes the inbound UDP packets it will accept.
  507. # It's applied to INPUT on the external or Internet interface.
  508. # Note that the stateful settings allow replies.
  509. # These rules are for new requests.
  510. # It drops netbios packets (windows) immediately without logging.
  511.  
  512. # Drop netbios calls
  513. # Please note that these rules do not really change the way the firewall
  514. # treats netbios connections.  Connections from the localhost and
  515. # internal interface (if one exists) are accepted by default.
  516. # Responses from the Internet to requests initiated by or through
  517. # the firewall are also accepted by default.  To get here, the
  518. # packets would have to be part of a new request received by the
  519. # Internet interface.  You would have to manually add rules to
  520. # accept these.  I added these rules because some network connections,
  521. # such as those via cable modems, tend to be filled with noise from
  522. # unprotected Windows machines.  These rules drop those packets
  523. # quickly and without logging them.  This prevents them from traversing
  524. # the whole chain and keeps the log from getting cluttered with
  525. # chatter from Windows systems.
  526. $IPT -A udp_inbound -p UDP -s 0/0 --destination-port 137 -j DROP
  527. $IPT -A udp_inbound -p UDP -s 0/0 --destination-port 138 -j DROP
  528.  
  529. # Dynamic Address
  530. # If DHCP, the initial request is a broadcast. The response
  531. # doesn't exactly match the outbound packet.  This explicitly
  532. # allow the DHCP ports to alleviate this problem.
  533. # If you receive your dynamic address by a different means, you
  534. # can probably comment this line.
  535. $IPT -A udp_inbound -p UDP -s 0/0 --source-port 67 --destination-port 68 \
  536.     -j ACCEPT
  537.  
  538.  
  539. # Not matched, so return for logging
  540. $IPT -A udp_inbound -p UDP -j RETURN
  541.  
  542. # udp_outbound chain
  543. #
  544. # This chain is used with a private network to prevent forwarding for
  545. # UDP requests on specific protocols.  Applied to the FORWARD rule from
  546. # the internal network.  Ends with an ACCEPT
  547.  
  548.  
  549. # No match, so ACCEPT
  550. $IPT -A udp_outbound -p UDP -s 0/0 -j ACCEPT
  551.  
  552. # tcp_inbound chain
  553. #
  554. # This chain is used to allow inbound connections to the
  555. # system/gateway.  Use with care.  It defaults to none.
  556. # It's applied on INPUT from the external or Internet interface.
  557.  
  558.  
  559. # Not matched, so return so it will be logged
  560. $IPT -A tcp_inbound -p TCP -j RETURN
  561.  
  562. # tcp_outbound chain
  563. #
  564. # This chain is used with a private network to prevent forwarding for
  565. # requests on specific protocols.  Applied to the FORWARD rule from
  566. # the internal network.  Ends with an ACCEPT
  567.  
  568.  
  569. # No match, so ACCEPT
  570. $IPT -A tcp_outbound -p TCP -s 0/0 -j ACCEPT
  571.  
  572. ###############################################################################
  573. #
  574. # INPUT Chain
  575. #
  576.  
  577. echo "Process INPUT chain ..."
  578.  
  579. # Allow all on localhost interface
  580. $IPT -A INPUT -p ALL -i $LO_IFACE -j ACCEPT
  581.  
  582. # Drop bad packets
  583. $IPT -A INPUT -p ALL -j bad_packets
  584.  
  585. # DOCSIS compliant cable modems
  586. # Some DOCSIS compliant cable modems send IGMP multicasts to find
  587. # connected PCs.  The multicast packets have the destination address
  588. # 224.0.0.1.  You can accept them.  If you choose to do so,
  589. # Uncomment the rule to ACCEPT them and comment the rule to DROP
  590. # them  The firewall will drop them here by default to avoid
  591. # cluttering the log.  The firewall will drop all multicasts
  592. # to the entire subnet (224.0.0.1) by default.  To only affect
  593. # IGMP multicasts, change '-p ALL' to '-p 2'.  Of course,
  594. # if they aren't accepted elsewhere, it will only ensure that
  595. # multicasts on other protocols are logged.
  596. # Drop them without logging.
  597. $IPT -A INPUT -p ALL -d 224.0.0.1 -j DROP
  598. # The rule to accept the packets.
  599. # $IPT -A INPUT -p ALL -d 224.0.0.1 -j ACCEPT
  600.  
  601. # Rules for the private network (accessing gateway system itself)
  602. $IPT -A INPUT -p ALL -i $LOCAL_IFACE -s $LOCAL_NET -j ACCEPT
  603. $IPT -A INPUT -p ALL -i $LOCAL_IFACE -d $LOCAL_BCAST -j ACCEPT
  604.  
  605.  
  606. # Inbound Internet Packet Rules
  607.  
  608. # Accept Established Connections
  609. $IPT -A INPUT -p ALL -i $INET_IFACE -m state --state ESTABLISHED,RELATED \
  610.     -j ACCEPT
  611.  
  612. $IPT -A INPUT -p ALL -i $INET_IFACE2 -m state --state ESTABLISHED,RELATED \
  613.     -j ACCEPT
  614.  
  615. # Route the rest to the appropriate user chain
  616. $IPT -A INPUT -p TCP -i $INET_IFACE -j tcp_inbound
  617. $IPT -A INPUT -p UDP -i $INET_IFACE -j udp_inbound
  618. $IPT -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
  619.  
  620. $IPT -A INPUT -p TCP -i $INET_IFACE2 -j tcp_inbound
  621. $IPT -A INPUT -p UDP -i $INET_IFACE2 -j udp_inbound
  622. $IPT -A INPUT -p ICMP -i $INET_IFACE2 -j icmp_packets
  623.  
  624. # Drop without logging broadcasts that get this far.
  625. # Cuts down on log clutter.
  626. # Comment this line if testing new rules that impact
  627. # broadcast protocols.
  628. $IPT -A INPUT -m pkttype --pkt-type broadcast -j DROP
  629.  
  630. # Log packets that still don't match
  631. $IPT -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
  632.    --log-prefix "INPUT packet died: "
  633.  
  634. ###############################################################################
  635. #
  636. # FORWARD Chain
  637. #
  638.  
  639. echo "Process FORWARD chain ..."
  640.  
  641. # Used if forwarding for a private network
  642.  
  643. # Drop bad packets
  644. $IPT -A FORWARD -p ALL -j bad_packets
  645.  
  646. # Accept TCP packets we want to forward from internal sources
  647. $IPT -A FORWARD -p tcp -i $LOCAL_IFACE -j tcp_outbound
  648.  
  649. # Accept UDP packets we want to forward from internal sources
  650. $IPT -A FORWARD -p udp -i $LOCAL_IFACE -j udp_outbound
  651.  
  652. # If not blocked, accept any other packets from the internal interface
  653. $IPT -A FORWARD -p ALL -i $LOCAL_IFACE -j ACCEPT
  654.  
  655. # Deal with responses from the internet
  656. $IPT -A FORWARD -i $INET_IFACE -m state --state ESTABLISHED,RELATED \
  657.     -j ACCEPT
  658.  
  659. $IPT -A FORWARD -i $INET_IFACE2 -m state --state ESTABLISHED,RELATED \
  660.     -j ACCEPT
  661.  
  662. # Log packets that still don't match
  663. $IPT -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG \
  664.    --log-prefix "FORWARD packet died: "
  665.  
  666. ###############################################################################
  667. #
  668. # OUTPUT Chain
  669. #
  670.  
  671. echo "Process OUTPUT chain ..."
  672.  
  673. # Generally trust the firewall on output
  674.  
  675. # However, invalid icmp packets need to be dropped
  676. # to prevent a possible exploit.
  677. $IPT -A OUTPUT -m state -p icmp --state INVALID -j DROP
  678.  
  679. # Localhost
  680. $IPT -A OUTPUT -p ALL -s $LO_IP -j ACCEPT
  681. $IPT -A OUTPUT -p ALL -o $LO_IFACE -j ACCEPT
  682.  
  683. # To internal network
  684. $IPT -A OUTPUT -p ALL -s $LOCAL_IP -j ACCEPT
  685. $IPT -A OUTPUT -p ALL -o $LOCAL_IFACE -j ACCEPT
  686.  
  687. # To internet
  688. $IPT -A OUTPUT -p ALL -o $INET_IFACE -j ACCEPT
  689.  
  690. $IPT -A OUTPUT -p ALL -o $INET_IFACE2 -j ACCEPT
  691.  
  692.  
  693. # Log packets that still don't match
  694. $IPT -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
  695.    --log-prefix "OUTPUT packet died: "
  696.  
  697. ###############################################################################
  698. #
  699. # nat table
  700. #
  701. ###############################################################################
  702.  
  703. # The nat table is where network address translation occurs if there
  704. # is a private network.  If the gateway is connected to the Internet
  705. # with a static IP, snat is used.  If the gateway has a dynamic address,
  706. # masquerade must be used instead.  There is more overhead associated
  707. # with masquerade, so snat is better when it can be used.
  708. # The nat table has a builtin chain, PREROUTING, for dnat and redirects.
  709. # Another, POSTROUTING, handles snat and masquerade.
  710.  
  711. echo "Load rules for nat table ..."
  712.  
  713. ###############################################################################
  714. #
  715. # PREROUTING chain
  716. #
  717.  
  718.  
  719. ###############################################################################
  720. #
  721. # POSTROUTING chain
  722. #
  723.  
  724. $IPT -t nat -A POSTROUTING -o $INET_IFACE -j MASQUERADE
  725.  
  726. $IPT -t nat -A POSTROUTING -o $INET_IFACE2 -j MASQUERADE
  727.  
  728. ###############################################################################
  729. #
  730. # mangle table
  731. #
  732. ###############################################################################
  733.  
  734. # The mangle table is used to alter packets.  It can alter or mangle them in
  735. # several ways.  For the purposes of this generator, we only use its ability
  736. # to alter the TTL in packets.  However, it can be used to set netfilter
  737. # mark values on specific packets.  Those marks could then be used in another
  738. # table like filter, to limit activities associated with a specific host, for
  739. # instance.  The TOS target can be used to set the Type of Service field in
  740. # the IP header.  Note that the TTL target might not be included in the
  741. # distribution on your system.  If it is not and you require it, you will
  742. # have to add it.  That may require that you build from source.
  743.  
  744. echo "Load rules for mangle table ..."
  745.  
  746.  

Разликите:

Код
GeSHi (Diff):
  1. 64a65
  2. > INET_IFACE2="eth1"
  3. 379a381,383
  4. > $IPT -A bad_packets -p ALL -i $INET_IFACE2 -s $LOCAL_NET -j LOG \
  5. >     --log-prefix "Illegal source: "
  6. >
  7. 381a386,387
  8. > $IPT -A bad_packets -p ALL -i $INET_IFACE2 -s $LOCAL_NET -j DROP
  9. >
  10. 605a612,614
  11. > $IPT -A INPUT -p ALL -i $INET_IFACE2 -m state --state ESTABLISHED,RELATED \
  12. >      -j ACCEPT
  13. >
  14. 610a620,623
  15. > $IPT -A INPUT -p TCP -i $INET_IFACE2 -j tcp_inbound
  16. > $IPT -A INPUT -p UDP -i $INET_IFACE2 -j udp_inbound
  17. > $IPT -A INPUT -p ICMP -i $INET_IFACE2 -j icmp_packets
  18. >
  19. 645a659,661
  20. > $IPT -A FORWARD -i $INET_IFACE2 -m state --state ESTABLISHED,RELATED \
  21. >      -j ACCEPT
  22. >
  23. 673a690,692
  24. > $IPT -A OUTPUT -p ALL -o $INET_IFACE2 -j ACCEPT
  25. >
  26. >
  27. 706a726,727
  28. > $IPT -t nat -A POSTROUTING -o $INET_IFACE2 -j MASQUERADE
  29. >
  30.  

Този код го налучках след няколкочасови проби-грешки.

На първия компютър имам главно NFS, sshd и Apache:

Код:
$ nmap -sT -PT 192.168.0.1

Starting Nmap 4.20 ( http://insecure.org ) at 2009-01-28 19:22 EET
Interesting ports on myrouter.interbild.net (192.168.0.1):
Not shown: 1690 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
37/tcp   open  time
80/tcp   open  http
111/tcp  open  rpcbind
113/tcp  open  auth
852/tcp  open  unknown
2049/tcp open  nfs

Nmap finished: 1 IP address (1 host up) scanned in 2.470 seconds

Целта ми е тези услуги да не са достъпни отвън.
Активен

laskov

  • Напреднали
  • *****
  • Публикации: 3166
    • Профил
//Извън темата: Що така си мисля, че си пребарал акаунта на vstoykov и пишеш от негово име?
Активен

Не си мислете, че понеже Вие мислите правилно, всички мислят като Вас! Затова, когато има избори, идете и гласувайте, за да не сте изненадани после от резултата, и за да не твърди всяка партия, че тя е спечелила, а Б.Б. (С.С., ...) е загубил, а трети да управлява.  Наздраве!  [_]3

vstoykov

  • Напреднали
  • *****
  • Публикации: 1286
  • Distribution: Ubuntu
  • Window Manager: Fluxbox
    • Профил
    • WWW
Никой не ми е откраднал акаунта. Може би те учудва това, че някой (в случая аз) би могъл да си признае, че не е компетентен в дадена област (в случая, че не разбирам iptables)? Не разбирам и от психология, затова не мога да коментирам дали това е нормално или не.
Активен

VladSun

  • Напреднали
  • *****
  • Публикации: 2166
    • Профил
Мможеш ли да дадеш изхода от
Код
GeSHi (Bash):
  1. iptables-save
Активен

KISS Principle ( Keep-It-Short-and-Simple )
http://openfmi.net/projects/flattc/
Има 10 вида хора на този свят - разбиращи двоичния код и тези, които не го разбират :P

vstoykov

  • Напреднали
  • *****
  • Публикации: 1286
  • Distribution: Ubuntu
  • Window Manager: Fluxbox
    • Профил
    • WWW
Код:
root@myrouter:~# iptables-save
# Generated by iptables-save v1.3.8 on Thu Jan 29 15:52:59 2009
*mangle
:PREROUTING ACCEPT [2020885:1520466744]
:INPUT ACCEPT [7571699:2257170031]
:FORWARD ACCEPT [13369161:10137085919]
:OUTPUT ACCEPT [18462:90434186]
:POSTROUTING ACCEPT [18505324:13527462954]
COMMIT
# Completed on Thu Jan 29 15:52:59 2009
# Generated by iptables-save v1.3.8 on Thu Jan 29 15:52:59 2009
*nat
:PREROUTING ACCEPT [289481:37144439]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [732:44523]
-A POSTROUTING -o ppp0 -j MASQUERADE
-A POSTROUTING -o eth1 -j MASQUERADE
COMMIT
# Completed on Thu Jan 29 15:52:59 2009
# Generated by iptables-save v1.3.8 on Thu Jan 29 15:52:59 2009
*filter
:INPUT DROP [1051:66565]
:FORWARD DROP [0:0]
:OUTPUT DROP [6:1176]
:bad_packets - [0:0]
:bad_tcp_packets - [0:0]
:icmp_packets - [0:0]
:tcp_inbound - [0:0]
:tcp_outbound - [0:0]
:udp_inbound - [0:0]
:udp_outbound - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -j bad_packets
-A INPUT -d 224.0.0.1 -j DROP
-A INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -j ACCEPT
-A INPUT -d 192.168.0.255 -i eth0 -j ACCEPT
-A INPUT -i ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i ppp0 -p tcp -j tcp_inbound
-A INPUT -i ppp0 -p udp -j udp_inbound
-A INPUT -i ppp0 -p icmp -j icmp_packets
-A INPUT -i eth1 -p tcp -j tcp_inbound
-A INPUT -i eth1 -p udp -j udp_inbound
-A INPUT -i eth1 -p icmp -j icmp_packets
-A INPUT -m pkttype --pkt-type broadcast -j DROP
-A INPUT -m limit --limit 3/min --limit-burst 3 -j LOG --log-prefix "INPUT packet died: "
-A FORWARD -j bad_packets
-A FORWARD -i eth0 -p tcp -j tcp_outbound
-A FORWARD -i eth0 -p udp -j udp_outbound
-A FORWARD -i eth0 -j ACCEPT
-A FORWARD -i ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m limit --limit 3/min --limit-burst 3 -j LOG --log-prefix "FORWARD packet died: "
-A OUTPUT -p icmp -m state --state INVALID -j DROP
-A OUTPUT -s 127.0.0.1 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -s 192.168.0.1 -j ACCEPT
-A OUTPUT -o eth0 -j ACCEPT
-A OUTPUT -o ppp0 -j ACCEPT
-A OUTPUT -o eth1 -j ACCEPT
-A OUTPUT -m limit --limit 3/min --limit-burst 3 -j LOG --log-prefix "OUTPUT packet died: "
-A bad_packets -s 192.168.0.0/255.255.255.0 -i ppp0 -j LOG --log-prefix "Illegal source: "
-A bad_packets -s 192.168.0.0/255.255.255.0 -i eth1 -j LOG --log-prefix "Illegal source: "
-A bad_packets -s 192.168.0.0/255.255.255.0 -i ppp0 -j DROP
-A bad_packets -s 192.168.0.0/255.255.255.0 -i eth1 -j DROP
-A bad_packets -m state --state INVALID -j LOG --log-prefix "Invalid packet: "
-A bad_packets -m state --state INVALID -j DROP
-A bad_packets -p tcp -j bad_tcp_packets
-A bad_packets -j RETURN
-A bad_tcp_packets -i eth0 -p tcp -j RETURN
-A bad_tcp_packets -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j LOG --log-prefix "New not syn: "
-A bad_tcp_packets -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j DROP
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j LOG --log-prefix "Stealth scan: "
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j LOG --log-prefix "Stealth scan: "
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,PSH,URG -j LOG --log-prefix "Stealth scan: "
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,PSH,URG -j DROP
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,ACK,URG -j LOG --log-prefix "Stealth scan: "
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,ACK,URG -j DROP
-A bad_tcp_packets -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j LOG --log-prefix "Stealth scan: "
-A bad_tcp_packets -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j LOG --log-prefix "Stealth scan: "
-A bad_tcp_packets -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
-A bad_tcp_packets -p tcp -j RETURN
-A icmp_packets -p icmp -f -j LOG --log-prefix "ICMP Fragment: "
-A icmp_packets -p icmp -f -j DROP
-A icmp_packets -p icmp -m icmp --icmp-type 8 -j DROP
-A icmp_packets -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A icmp_packets -p icmp -j RETURN
-A tcp_inbound -p tcp -j RETURN
-A tcp_outbound -p tcp -j ACCEPT
-A udp_inbound -p udp -m udp --dport 137 -j DROP
-A udp_inbound -p udp -m udp --dport 138 -j DROP
-A udp_inbound -p udp -m udp --sport 67 --dport 68 -j ACCEPT
-A udp_inbound -p udp -j RETURN
-A udp_outbound -p udp -j ACCEPT
COMMIT
# Completed on Thu Jan 29 15:53:00 2009
root@myrouter:~#   
Активен

VladSun

  • Напреднали
  • *****
  • Публикации: 2166
    • Профил
Гледаме конкретно:
Код
GeSHi (Bash):
  1. *filter
  2. :INPUT DROP [1051:66565]
  3. ...
  4. -A INPUT -j bad_packets
  5. ...
  6. -A INPUT -i ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  7. -A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
  8.  
  9. -A INPUT -i ppp0 -p tcp -j tcp_inbound
  10. ...
  11. -A INPUT -i eth1 -p tcp -j tcp_inbound
  12. ...
  13.  
  14. -A tcp_inbound -p tcp -j RETURN

Т.е. INPUT политиката е DROP. След това имаме филтър за лоши пакети.  За eth0 и ppp0 интерфейсите разрешаваш само връзките започнати от тяхна страна - т.е. всички TCP SYN пакети и всички "първи" UDP пакети няма да се ACCEPT-нат и при достигане на последното правило ще бъдат DROP-нати заради политиката. Веригата tcp_inbound де факто е "празна" - т.е. няма правила в нея, които да действат върху пакетите.
Ако те разбирам правилно, искаш през интерфейса ppp0 да се виждат услугите, докато през eth1 да не се виждат.
Тогава трябва да промениш правилото:
Код
GeSHi (Bash):
  1. -A INPUT -i ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
на
Код
GeSHi (Bash):
  1. -A INPUT -p tcp -i ppp0 -j ACCEPT
или да вмъкнеш подобно в tcp_inbound.

Пакетите през eth1 в момента са както искаш - машината няма отворен порт към Интернет.

Само да отбележа, че в момента рискуваш да получиш огромен лог файл, ако някой реши да те атакува - всички правила във веригата bad_packets от вида:
Код
GeSHi (Bash):
  1. -A bad_tcp_packets -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -j LOG --log-prefix "New not syn: "
Трябва да се заменят със:
Код
GeSHi (Bash):
  1. -A bad_tcp_packets -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m state --state NEW -m limit --limit 3/min --limit-burst 3 -j LOG --log-prefix "New not syn: "

ПП: За проверка: https://www.grc.com/x/ne.dll?bh0bkyd2
« Последна редакция: Jan 29, 2009, 15:22 от VladSun »
Активен

KISS Principle ( Keep-It-Short-and-Simple )
http://openfmi.net/projects/flattc/
Има 10 вида хора на този свят - разбиращи двоичния код и тези, които не го разбират :P

vstoykov

  • Напреднали
  • *****
  • Публикации: 1286
  • Distribution: Ubuntu
  • Window Manager: Fluxbox
    • Профил
    • WWW
Ако те разбирам правилно, искаш през интерфейса ppp0 да се виждат услугите, докато през eth1 да не се виждат.

Благодаря за отговора.

В същност искам услугите да се виждат само от втория компютър (настройките за ppp0 и eth1 да са еднакви, ако е възможно - като за Интернет). ppp0 се явява Интернет както и eth1 (разликата е, че ppp0 води към компютър в Швейцария - вж. http://www.swissvpn.net/ - моя доставчик на Интернет ми дава вътрешен IP адрес, който не е публичен; освен това може би стотици други клиенти на този доставчик ползват един и същ публичен IP адрес и имам проблеми с някои сайтове (напр. ftp сървъра на Lunarpages) - явно са баннали мрежата ми по IP; доставчика ми на Интернет иска още пари за преминаване на бизнес план, който позволява VPN и затова смятам да ползвам алтернативен VPN от Швейцария (или ако не съм доволен - от друг доставчик - има много такива)). Другата алтернатива е да мина на БТК, но нещо не ми вдъхват доверие...

В бъдеще смятам да пускам трети компютър, който ще е от вътрешната мрежа (напр. eth2, 192.168.0.3). Той ще бъде също от вътрешната мрежа, но не трябва да има достъп до услугите на първия компютър а само до Интернет.

А мога ли просто да махна "LOG --log-prefix "New not syn: "" за да няма логове? В момента syslog ми е 70MB...
« Последна редакция: Jan 29, 2009, 21:20 от vstoykov »
Активен

VladSun

  • Напреднали
  • *****
  • Публикации: 2166
    • Профил
Ако те разбирам правилно, искаш през интерфейса ppp0 да се виждат услугите, докато през eth1 да не се виждат.

Благодаря за отговора.

В същност искам услугите да се виждат само от втория компютър (настройките за ppp0 и eth1 да са еднакви, ако е възможно - като за Интернет). ppp0 се явява Интернет както и eth1 (разликата е, че ppp0 води към компютър в Швейцария - вж. http://www.swissvpn.net/ - моя доставчик на Интернет ми дава вътрешен IP адрес, който не е публичен - на него са вързани може би стотици други клиенти на този доставчик и имам проблеми с някои сайтове - явно са баннали мрежата ми по IP; доставчика ми на Интернет иска още пари за преминаване на бизнес план, който позволява VPN и затова смятам да ползвам алтернативен VPN от Швейцария (или ако не съм доволен - от друг доставчик - има много такива)). Другата алтернатива е да мина на БТК, но нещо не ми вдъхват доверие...

Значи в това отношение защитната стена, която си публикувал е ОК.

В бъдеще смятам да пускам трети компютър, който ще е от вътрешната мрежа (напр. eth2, 192.168.0.3). Той ще бъде също от вътрешната мрежа, но не трябва да има достъп до услугите на първия компютър а само до Интернет.

Тогава трябва да промениш:
Код
GeSHi (Bash):
  1. -A INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -j ACCEPT
на
Код
GeSHi (Bash):
  1. -A INPUT -s 192.168.0.2 -i eth0 -j ACCEPT

А мога ли просто да махна "LOG --log-prefix "New not syn: "" за да няма логове? В момента syslog ми е 70MB...

Както подчертах - говоря за всички подобни правила в bad_*_packets веригите. Ако не искаш логове просто махни от тази верига всички правила завъшващи на "-j LOG ...." :)
« Последна редакция: Jan 29, 2009, 16:17 от VladSun »
Активен

KISS Principle ( Keep-It-Short-and-Simple )
http://openfmi.net/projects/flattc/
Има 10 вида хора на този свят - разбиращи двоичния код и тези, които не го разбират :P

vstoykov

  • Напреднали
  • *****
  • Публикации: 1286
  • Distribution: Ubuntu
  • Window Manager: Fluxbox
    • Профил
    • WWW
Благодаря. Махнах всичко, което има "-j LOG". И без това не ги чета.

Активен