Guest User

Untitled

a guest
Mar 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.51 KB | None | 0 0
  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="/sbin/iptables"
  60. IPTS="/sbin/iptables-save"
  61. IPTR="/sbin/iptables-restore"
  62.  
  63. # Internet Interface
  64. INET_IFACE="ens33"
  65.  
  66. # Local Interface Information
  67. LOCAL_IFACE="ens33:0"
  68. LOCAL_IP="10.1.20.1"
  69. LOCAL_NET="10.1.20.0/24"
  70. LOCAL_BCAST="10.1.20.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 ..."
Advertisement
Add Comment
Please, Sign In to add comment