Advertisement
Guest User

Active Bypass

a guest
Jan 15th, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. ## CUSTOMIZE YOUR SCRIPT VARIABLES
  2. #
  3. ## Uncomment and set value(s) as needed to customize your rules
  4. #
  5. # IP ADRESS RANGE OR SINGLE IP ADDRESS
  6. #ip_src_lst="192.168.1.104-192.168.1.106 192.168.1.15"
  7. #ip_src_lst="192.168.1.9 192.168.1.29"
  8. #ip_dst_lst=""
  9. ## CIDR NOTATION or SINGLE IP ADDRESS - E. G. "98.207.0.0/16 74.125.229.0/24 80.130.125.163"
  10. #cidr_src_rnge=""
  11. #cidr_dst_rnge=""
  12.  
  13. #################################################################
  14. # CHANGE MARK VALUE(S) (0 or 1) IN FOR LOOPS BELOW IF NECESSARY #
  15. #################################################################
  16.  
  17. # SHELL COMMANDS FOR MAINTENANCE.
  18. # DO NOT UNCOMMENT, THESE ARE INTENDED TO BE USED IN A SHELL COMMAND LINE
  19. #
  20. # List Contents by line number
  21. # iptables -L PREROUTING -t mangle -n --line-numbers
  22. #
  23. # Delete rules from mangle by line number
  24. # iptables -D PREROUTING type-line-number-here -t mangle
  25. #
  26. # To list the current rules on the router, issue the command:
  27. # iptables -t mangle -L PREROUTING
  28. #
  29. # Flush/reset all the rules to default by issuing the command:
  30. # iptables -t mangle -F PREROUTING
  31.  
  32. #
  33. # First it is necessary to disable Reverse Path Filtering on all
  34. # current and future network interfaces:
  35. #
  36. for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do
  37. echo 0 > $i
  38. done
  39.  
  40. #
  41. # Delete table 100 and flush any existing rules if they exist.
  42. #
  43. ip route flush table 100
  44. ip route del default table 100
  45. ip rule del fwmark 1 table 100
  46. ip route flush cache
  47. iptables -t mangle -F PREROUTING
  48.  
  49. #
  50. # Let's find out the tunnel interface
  51. #
  52. iface_lst=`route | awk ' {print $8}'`
  53. for tun_if in $iface_lst; do
  54. if [ $tun_if == "tun11" ] || [ $tun_if == "tun12" ] || [ $tun_if == "ppp0" ]; then
  55. break
  56. fi
  57. done
  58.  
  59. #
  60. # Copy all non-default and non-VPN related routes from the main table into table 100.
  61. # Then configure table 100 to route all traffic out the WAN gateway and assign it mark "1"
  62. #
  63. ip route show table main | grep -Ev ^default | grep -Ev $tun_if \
  64. | while read ROUTE ; do
  65. ip route add table 100 $ROUTE
  66. done
  67. ip route add default table 100 via $(nvram get wan_gateway)
  68. ip rule add fwmark 1 table 100
  69. ip route flush cache
  70.  
  71. # EXAMPLES:
  72. #
  73. # All LAN traffic will bypass the VPN (Useful to put this rule first,
  74. # so all traffic bypasses the VPN and you can configure exceptions afterwards)
  75. # iptables -t mangle -A PREROUTING -i br0 -j MARK --set-mark 1
  76. #
  77. # Ports 80 and 443 will bypass the VPN
  78. # iptables -t mangle -A PREROUTING -i br0 -p tcp -m multiport --dport 80,443 -j MARK --set-mark 1
  79. #
  80. # All traffic from a particular computer on the LAN will use the VPN
  81. # iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 192.168.1.2 -j MARK --set-mark 0
  82. #
  83. # All traffic to a specific Internet IP address will use the VPN
  84. # iptables -t mangle -A PREROUTING -i br0 -m iprange --dst-range 216.146.38.70 -j MARK --set-mark 0
  85. #
  86. # All traffic from a specific Internet IP address range USING CIDR NOTATION will bypass the VPN
  87. # iptables -t mangle -A PREROUTING -i br0 -s 74.125.229.0/24 -j MARK --set-mark 0
  88. #
  89. # All traffic to a specific Internet IP address range USING CIDR NOTATION will use the VPN
  90. # iptables -t mangle -A PREROUTING -i br0 -d 98.207.0.0/16 -j MARK --set-mark 0
  91. #
  92. # All UDP and ICMP traffic will bypass the VPN
  93. # iptables -t mangle -A PREROUTING -i br0 -p udp -j MARK --set-mark 1
  94. # iptables -t mangle -A PREROUTING -i br0 -p icmp -j MARK --set-mark 1
  95.  
  96. # Default behavior: MARK = 1 all traffic bypasses VPN, MARK = 0 all traffic goes VPN
  97. iptables -t mangle -A PREROUTING -i br0 -j MARK --set-mark 0
  98.  
  99. for ip_addrs in $ip_src_lst ; do
  100. iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range "$ip_addrs" -j MARK --set-mark 1
  101. done
  102.  
  103. for ip_addrs in $ip_dst_lst ; do
  104. iptables -t mangle -A PREROUTING -i br0 -m iprange --dst-range "$ip_addrs" -j MARK --set-mark 0
  105. done
  106.  
  107. for ip_rnge in $cidr_src_rnge ; do
  108. iptables -t mangle -A PREROUTING -i br0 -s "$ip_rnge" -j MARK --set-mark 0
  109. done
  110.  
  111. for ip_rnge in $cidr_dst_rnge ; do
  112. iptables -t mangle -A PREROUTING -i br0 -d "$ip_rnge" -j MARK --set-mark 0
  113. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement