You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

  1. #!/bin/bash
  2. #
  3. OLD_NAME=vague-router
  4. HNAME=gateway
  5. apt-get update
  6. sed -i "s/#VAGRANT-END/up route add -net 192.168.0.0\/16 gw 192.168.1.254 dev enp0s8/g" /etc/network/interfaces
  7. # Disable rp_filter and enable forwarding for routers
  8. #
  9. echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
  10. echo "net.ipv4.conf.all.rp_filter=0" >> /etc/sysctl.conf
  11. echo "net.ipv4.conf.default.rp_filter=0" >> /etc/sysctl.conf
  12. echo "net.ipv4.conf.lo.rp_filter=0" >> /etc/sysctl.conf
  13. echo "net.ipv4.conf.enp0s3.rp_filter=0" >> /etc/sysctl.conf
  14. echo "net.ipv4.conf.enp0s8.rp_filter=0" >> /etc/sysctl.conf
  15. echo "net.ipv4.conf.enp0s9.rp_filter=0" >> /etc/sysctl.conf
  16. sysctl -p
  17. echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
  18. echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
  19. sudo apt-get install iptables-persistent -y
  20. echo Flusing any old iptables rules..
  21. sudo iptables -F
  22. sudo iptables --table nat -F
  23. sudo iptables --delete-chain
  24. sudo iptables --table nat --delete-chain
  25. echo Adding forward and masquerade rule for NATing
  26. sudo iptables -t nat --append POSTROUTING --out-interface enp0s8 -j MASQUERADE
  27. sudo iptables --append FORWARD --in-interface enp0s9 -j ACCEPT
  28. echo Saving the current iptables config..
  29. sudo netfilter-persistent save
  30. sed -i "s/$OLD_NAME/$HNAME/g" /etc/hostname
  31. sed -i "s/$OLD_NAME/$HNAME/g" /etc/hosts
  32. hostname $HNAME
  33. exit