Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. eth0: -ip 10.0.0.1 -net 10.0.0.0/8 -gw 10.0.0.1 (the servers own intf)
  2. eth1: -ip 192.168.1.74 -net 192.168.1.0/24 -gw 192.168.1.254
  3. eth2: -ip 192.168.1.91 -net 192.168.0.0/24 -gw 192.168.0.1
  4.  
  5. modprobe iptable_nat
  6. modprobe ip_conntrack
  7.  
  8. echo "1" > /proc/sys/net/ipv4/ip_forward
  9.  
  10. iptables -P INPUT ACCEPT
  11. iptables -F INPUT
  12. iptables -P OUTPUT ACCEPT
  13. iptables -F OUTPUT
  14. iptables -P FORWARD DROP
  15. iptables -F FORWARD
  16. iptables -F PREROUTING
  17. iptables -t nat -F
  18. iptables -t mangle -F
  19. iptables -F
  20. # This next line, restores any issues trying to connect to something
  21. # if you get weird ACK packets when trying to connect (at least i did)!
  22. iptables -t mangle -A PREROUTING -p tcp -j CONNMARK --restore-mark
  23. ip route flush table main
  24.  
  25. iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 22 -j MARK --set-mark 1
  26. ### iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 80 -j MARK --set-mark 1
  27. iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 4070 -j MARK --set-mark 1
  28.  
  29. ## Setup routes
  30. # LAN
  31. route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
  32. # ADSL
  33. route add -net 192.168.1.0 netmask 255.255.255.0 dev eth1
  34. # 4G (Only accessible if marking packages with x01
  35. route add -net 192.168.0.0 netmask 255.255.255.0 dev eth2
  36. # Default via ADSL
  37. ## -- Does the same as ip route below? route add default gw 192.168.1.254
  38.  
  39.  
  40. echo "201 eth2.out" >> /etc/iproute2/rt_tables
  41.  
  42. ip rule add fwmark 1 table eth2.out
  43. ip route add default via 192.168.0.1 dev eth2 table eth2.out
  44. ip route add default via 192.168.1.254 dev eth1
  45.  
  46.  
  47.  
  48. ## Setup forwards
  49. # From 4G to LAN
  50. iptables -A FORWARD -i eth2 -o eth0 -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
  51. # From ADSL to LAN
  52. iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
  53. # From LAN to ADSL (Default route out)
  54. # - Note: If marked packages is sent to ADSL they will be mangled and rerouted to 4G
  55. iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
  56. iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
  57. iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
  58.  
  59. Ignore everything below unless you're interested in retracing my steps!!
  60.  
  61. #!/bin/bash
  62.  
  63. ## routing tables
  64. # wireless = 4G via eth2
  65. # adsl = adsl via eth1
  66.  
  67. modprobe iptable_nat
  68. modprobe ip_conntrack
  69.  
  70. echo "1" > /proc/sys/net/ipv4/ip_forward
  71.  
  72. iptables -P INPUT ACCEPT
  73. iptables -F INPUT
  74. iptables -P OUTPUT ACCEPT
  75. iptables -F OUTPUT
  76. iptables -P FORWARD DROP
  77. iptables -F FORWARD
  78. iptables -t nat -F
  79. ip route flush table main
  80. ip route flush table wireless
  81. ip route flush table adsl
  82.  
  83. ## Setup routing tables
  84. # ADSL
  85. ip route add table adsl to 192.168.1.0/24 dev eth1
  86. # 4G
  87. ip route add table wireless to 192.168.0.0 dev eth2
  88. ip rule add fwmark 0x1 table wireless
  89.  
  90. ## Setup routes
  91. # LAN
  92. route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
  93. # ADSL
  94. route add -net 192.168.1.0 netmask 255.255.255.0 dev eth1
  95. # 4G (Only accessible if marking packages with x01
  96. route add -net 192.168.0.0 netmask 255.255.255.0 dev eth2
  97. # Default via ADSL
  98. route add default gw 192.168.1.254
  99.  
  100.  
  101. ## Forward ports into the LAN
  102. iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j DNAT --to 10.0.0.3:80
  103.  
  104.  
  105. ## Lets mark all packets we want for 4G forward
  106. # HTTPS
  107. iptables -A OUTPUT -t mangle -o eth1 -p tcp --dport 443 -j MARK --set-mark 1
  108. # HTTP
  109. iptables -A OUTPUT -t mangle -o eth1 -p tcp --dport 80 -j MARK --set-mark 1
  110. # Spotify
  111. iptables -A OUTPUT -t mangle -o eth1 -p tcp --dport 4070 -j MARK --set-mark 1
  112.  
  113. ## Setup forwards
  114. # From 4G to LAN
  115. iptables -A FORWARD -i eth2 -o eth0 -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
  116. # From ADSL to LAN
  117. iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
  118. # From LAN to ADSL (Default route out)
  119. # - Note: If marked packages is sent to ADSL they will be mangled and rerouted to 4G
  120. iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
  121. iptables -A FORWARD -j LOG
  122. #iptables --table nat --append POSTROUTING --out-interface eth2 --jump SNAT --to-source "192.168.1.74"
  123. iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
  124.  
  125. iptables -t nat -A POSTROUTING -o eth2 -p tcp --dport 80 -j SNAT --to "192.168.0.91"
  126. iptables -t nat -A POSTROUTING -o eth2 -p tcp --dport 443 -j SNAT --to "192.168.0.91"
  127. iptables -t nat -A POSTROUTING -o eth2 -p tcp --dport 4070 -j SNAT --to "192.168.0.91"
  128.  
  129. iptables -A PREROUTING -t mangle -i eth0 -p tcp --dport 80 -j MARK --set-mark 1
  130.  
  131. ## Lets mark all packets we want for 4G forward
  132. # HTTPS
  133. iptables -A POSTROUTING -t mangle -o eth1 -p tcp --dport 443 -j MARK --set-mark 1
  134. # HTTP
  135. iptables -A POSTROUTING -t mangle -o eth1 -p tcp --dport 80 -j MARK --set-mark 1
  136. # Spotify
  137. iptables -A POSTROUTING -t mangle -o eth1 -p tcp --dport 4070 -j MARK --set-mark 1
  138.  
  139. root@Netbridge:~# route -n Kernel IP routing table Destination
  140.  
  141. Gateway Genmask Flags Metric Ref Use Iface<br>
  142. 0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eth1<br>
  143. 10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth0<br>
  144. 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2<br>
  145. 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
  146.  
  147. root@Netbridge:~# ifconfig
  148.  
  149. eth0 Link encap:Ethernet HWaddr 00:0c:29:7e:9e:4e
  150. inet addr:10.0.0.1 Bcast:10.255.255.255 Mask:255.0.0.0
  151.  
  152. eth1 Link encap:Ethernet HWaddr 00:0c:29:7e:9e:58
  153. inet addr:192.168.1.74 Bcast:192.168.1.255 Mask:255.255.255.0
  154.  
  155. eth2 Link encap:Ethernet HWaddr 00:0c:29:7e:9e:62
  156. inet addr:192.168.0.91 Bcast:192.168.0.255 Mask:255.255.255.0
  157.  
  158. route add default gw 192.168.1.254
  159.  
  160. 0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eth1
  161.  
  162. MASQUERADE
  163.  
  164. sysctl -w net.ipv4.conf.eth1.rp_filter=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement