eibgrad

ddwrt-whitelist-ip-289277.sh

Jan 25th, 2016 (edited)
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.28 KB | None | 0 0
  1. #!/bin/sh
  2. # http://www.dd-wrt.com/phpBB2/viewtopic.php?t=289277
  3.  
  4. #BLOCKED_NET="br0"  # private network
  5. BLOCKED_NET="br1"   # guest network
  6. #BLOCKED_NET="br+"  # all networks (private and guest)
  7.  
  8. # build the whitelist database
  9. WL="
  10. 157.166.226.26    # cnn.com
  11. 209.102.213.14    # mlb.com
  12. #96.17.202.227     # newegg.com
  13. ipchicken.com
  14. amazon.com
  15. frys.com
  16. www.facebook.com
  17. www.google.com
  18. "
  19.  
  20. WL_CHAIN="whitelist"
  21.  
  22. # cleanup from prior execution (precautionary)
  23. (
  24. iptables -D FORWARD -p tcp -i $BLOCKED_NET ! --dport 53 -m state --state NEW -j $WL_CHAIN
  25. iptables -F $WL_CHAIN
  26. iptables -X $WL_CHAIN
  27. ) 2>/dev/null
  28.  
  29. # create the whitelist chain
  30. iptables -N $WL_CHAIN
  31.  
  32. # load the whitelist chain
  33. OIFS="$IFS"; IFS=$'\n'
  34. for ip in $WL; do
  35.     if [ ${ip:0:1} != '#' ]; then # ignore comments
  36.         iptables -A $WL_CHAIN -d $(echo $ip | sed 's:#.*$::g') -j RETURN
  37.     fi
  38. done
  39. IFS="$OIFS"
  40. iptables -A $WL_CHAIN -p tcp -j REJECT --reject-with tcp-reset
  41. iptables -A $WL_CHAIN -j REJECT --reject-with icmp-host-prohibited
  42.  
  43. # trap new connections and check destination against whitelist (always allow DNS)
  44. iptables -I FORWARD -p tcp -i $BLOCKED_NET ! --dport 53 -m state --state NEW -j $WL_CHAIN
  45.  
  46. # review our handiwork
  47. iptables -vnL FORWARD | grep $WL_CHAIN
  48. iptables -vnL $WL_CHAIN
Add Comment
Please, Sign In to add comment