Guest User

Untitled

a guest
Jul 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.20 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. INTIF="eth2"
  4. EXTIF="eth1"
  5.  
  6. INTNET="192.168.0.0/24"
  7. INTIP="192.168.0.254/24"
  8. EXTIP="10.255.26.10"
  9.  
  10. PROXYSERVER="10.255.26.220"
  11. PROXYPORT="3128"
  12.  
  13. #EXTIP="`/sbin/ifconfig eth1 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
  14.  
  15. /sbin/depmod -a
  16. # Force loading and activation of all the NAT and IPTables needed modules
  17. /sbin/modprobe ip_tables
  18. /sbin/modprobe ip_conntrack
  19. /sbin/modprobe ip_conntrack_ftp
  20. /sbin/modprobe ip_conntrack_irc
  21. /sbin/modprobe iptable_nat
  22. /sbin/modprobe ip_nat_ftp
  23. /sbin/modprobe ip_nat_irc
  24.  
  25. echo "1" > /proc/sys/net/ipv4/ip_forward
  26. echo "1" > /proc/sys/net/ipv4/ip_dynaddr
  27.  
  28. UNIVERSE="0.0.0.0/0"
  29.  
  30. # Clearing any existing rules and setting default policy
  31. iptables -P INPUT ACCEPT
  32. iptables -F INPUT
  33. iptables -P OUTPUT ACCEPT
  34. iptables -F OUTPUT
  35. iptables -P FORWARD DROP
  36. iptables -F FORWARD
  37. iptables -t nat -F
  38.  
  39. # Flush the user chain.. if it exists
  40. if [ "`iptables -L | grep drop-and-log-it`" ]; then
  41.    iptables -F drop-and-log-it
  42. fi
  43.  
  44. # Delete all User-specified chains
  45. iptables -X
  46.  
  47. # Reset all IPTABLES counters
  48. iptables -Z
  49.  
  50. # Creating a DROP chain
  51. iptables -N drop-and-log-it
  52. iptables -A drop-and-log-it -j LOG --log-level info
  53. iptables -A drop-and-log-it -j REJECT
  54.  
  55. # ================ INPUT Chain ================
  56. # loopback interfaces are valid.
  57. iptables -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
  58.  
  59. # local interface, local machines, going anywhere is valid
  60. iptables -A INPUT -i $INTIF -s $INTNET -d $UNIVERSE -j ACCEPT
  61.  
  62. # remote interface, claiming to be local machines, IP spoofing, get lost
  63. iptables -A INPUT -i $EXTIF -s $INTNET -d $UNIVERSE -j drop-and-log-it
  64.  
  65. # remote interface, any source, going to permanent PPP address is valid
  66. iptables -A INPUT -i $EXTIF -s $UNIVERSE -d $EXTIP -j ACCEPT
  67.  
  68. # Allow any related traffic coming back to the MASQ server in
  69. iptables -A INPUT -i $EXTIF -s $UNIVERSE -d $EXTIP -m state --state ESTABLISHED,RELATED -j ACCEPT
  70.  
  71. # Catch all rule, all other incoming is denied and logged.
  72. iptables -A INPUT -s $UNIVERSE -d $UNIVERSE -j drop-and-log-it
  73.  
  74. # ================ OUTPUT Chain ================
  75. # loopback interface is valid.
  76. iptables -A OUTPUT -o lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
  77.  
  78. # local interfaces, any source going to local net is valid
  79. iptables -A OUTPUT -o $INTIF -s $EXTIP -d $INTNET -j ACCEPT
  80.  
  81. # local interface, any source going to local net is valid
  82. iptables -A OUTPUT -o $INTIF -s $INTIP -d $INTNET -j ACCEPT
  83.  
  84. # outgoing to local net on remote interface, stuffed routing, deny
  85. iptables -A OUTPUT -o $EXTIF -s $UNIVERSE -d $INTNET -j drop-and-log-it
  86.  
  87. # anything else outgoing on remote interface is valid
  88. iptables -A OUTPUT -o $EXTIF -s $EXTIP -d $UNIVERSE -j ACCEPT
  89.  
  90. # Catch all rule, all other outgoing is denied and logged.
  91. iptables -A OUTPUT -s $UNIVERSE -d $UNIVERSE -j drop-and-log-it
  92.  
  93. # ================ FORWARD Chain ================
  94. iptables -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
  95. iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT
  96.  
  97. # Enabling SNAT (MASQUERADE) functionality on $EXTIF
  98. iptables -t nat -A PREROUTING -s $INTNET -p tcp --dport 80 -j REDIRECT --to-ports $PROXYPORT
  99. iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
Add Comment
Please, Sign In to add comment