linux-as-a-router.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # external network
  3. : this is the address provided by Mediacom Cable
  4. : "173.29.124.66/21 brd 173.29.127.255"
  5. : "UPDATE on 2020 Dec 15th mediacom issued new lease before old expired
  6. 173.31.30.236/21 and the internet on the other computers went 'out'
  7. to fix it the nat needs to forward packets using the new address
  8. wes added a new rule for
  9. iptables -t nat -A POSTROUTING -o enp6s0 -j SNAT --to-source 173.31.30.236;
  10. then it did not work, but this is because there were two rule for the same thing
  11. iptables -t nat -L --line-numbers
  12. then look for the line number of the previous matching rule
  13. then delete it
  14. iptables -t nat -D POSTROUTING 1
  15. "
  16. # local network
  17. : this is a random number that matches the SurfBoard Modem
  18. : "local address inet 192.168.100.10/24"
  19. # Hardware
  20. : "ethernet adapter" "enp6s0 b8:70:f4:a6:62:e8"
  21. : "unused wifi adapter" "wlp7s0 92:01:0f:e1:90:20"
  22. # STEP 1
  23. : "# add network addresses computer" "
  24. ip addr add 192.168.100.10/24 dev enp6s0;
  25. ip addr add 173.29.124.66/21 dev enp6s0;
  26. "
  27. # STEP 2
  28. : "# add a route to the internet gateway" "
  29. ip route add default via 173.29.120.1 dev enp6s0;
  30. "
  31. # STEP 3
  32. : "# add NAT" "
  33. iptables -F; # this actually removes previous rules
  34. iptables -t nat -F;
  35. iptables -P INPUT ACCEPT;
  36. iptables -P OUTPUT ACCEPT;
  37. iptables -P FORWARD DROP;
  38. "
  39. # STEP 4
  40. : "# add the LAN side of NAT" "
  41. iptables -t nat -A POSTROUTING -o enp6s0 -j SNAT --to-source 173.29.124.66;
  42. iptables -A FORWARD -i enp6s0 -o enp6s0 -s 192.168.100.0/24 -j ACCEPT;
  43. iptables -A FORWARD -i enp6s0 -o enp6s0 -m state --state ESTABLISHED,RELATED -j ACCEPT;
  44. "
  45. # STEP 5
  46. : "# enable kernel forwarding module" "
  47. echo 1 >/proc/sys/net/ipv4/ip_forward;
  48. "
  49. # STEP 5.5
  50. : "# enable pptp for soheyl's Synology VPN" "
  51. ## probably needs conntrack installed....
  52. ## this adds conntection tracking to outbound Msft GRE (invalid tcp)
  53. ## packets and converts them into ESTABLISHED,RELATED
  54. iptables -t nat -A OUTPUT -p tcp --dport 1723 -j CT --helper pptp
  55. "
  56. ### TROUBLESHOOTING
  57. : "test if forwarding is enabled (1 is enabled, 0 not)" "
  58. sysctl net.ipv4.ip_forward
  59. "
  60. : "MS PPTP stuff" "
  61. ### [!] actually ignore this, use the instructions for pptp above ###
  62. # modprobe the following:
  63. # ip_nat_pptp -> alias for nf_nat_pptp
  64. # ip_conntrack_pptp (probably not needed loaded as dep for above)
  65. # ip_gre (probably not needed loaded as dep for above)
  66. # install conntrack software
  67. # sudo apt install conntrack
  68. # Kernel 4.7 and net.netfilter.nf_conntack_helper = 0 is default
  69. # someone decided that nf_conntrack_helper should not be enabled
  70. # edit /etc/sysctl.conf add:
  71. # net.netfilter.nf_conntrack_helper = 1
  72. # then reload: sysctl -p
  73. "
  74. : "MS PPTP part II" "
  75. it turns out that the nf_conntrack_helper module enables too many security issues
  76. and the consensus is to turn off the shotgun and instead enable security issues
  77. on a one-by-one basis, for PPTP:
  78. iptables -t raw -A OUTPUT -p tcp --dport 1723 -j CT --helper pptp
  79. "