Guest User

Untitled

a guest
Dec 5th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. # Requirements
  2. # debian/ubuntu
  3.  
  4. apt-get -y update && apt-get -y upgrade
  5. apt-get -y install strongswan xl2tpd libstrongswan-standard-plugins libstrongswan-extra-plugins
  6.  
  7. # Setup variables for L2TP connestion
  8. VPN_SERVER_IP=''
  9. VPN_IPSEC_PSK=''
  10. VPN_USER=''
  11. VPN_PASSWORD=''
  12. VPN_CONNETCTION_NAME='VPN1'
  13.  
  14. cat > /etc/ipsec.conf <<EOF
  15. config setup
  16. conn %default
  17. ikelifetime=60m
  18. keylife=20m
  19. rekeymargin=3m
  20. keyingtries=1
  21. keyexchange=ikev1
  22. authby=secret
  23.  
  24. conn $VPN_CONNETCTION_NAME
  25. keyexchange=ikev1
  26. left=%defaultroute
  27. auto=add
  28. authby=secret
  29. type=transport
  30. leftprotoport=17/1701
  31. rightprotoport=17/1701
  32. right=$VPN_SERVER_IP
  33. EOF
  34.  
  35. cat > /etc/ipsec.secrets <<EOF
  36. : PSK "$VPN_IPSEC_PSK"
  37. EOF
  38.  
  39. chmod 600 /etc/ipsec.secrets
  40.  
  41. cat > /etc/xl2tpd/xl2tpd.conf <<EOF
  42. [lac $VPN_CONNETCTION_NAME]
  43. lns = $VPN_SERVER_IP
  44. ppp debug = yes
  45. pppoptfile = /etc/ppp/options.l2tpd.client
  46. length bit = yes
  47. EOF
  48.  
  49. cat > /etc/ppp/options.l2tpd.client <<EOF
  50. ipcp-accept-local
  51. ipcp-accept-remote
  52. refuse-eap
  53. require-chap
  54. noccp
  55. noauth
  56. mtu 1280
  57. mru 1280
  58. noipdefault
  59. defaultroute
  60. usepeerdns
  61. connect-delay 5000
  62. name $VPN_USER
  63. # Better to use /etc/ppp/chap-secrets file for storing password
  64. #password $VPN_PASSWORD
  65. remotename L2TP
  66. EOF
  67.  
  68. chmod 600 /etc/ppp/options.l2tpd.client
  69.  
  70. echo "${VPN_USER} L2TP ${VPN_PASSWORD} *" >> /etc/ppp/chap-secrets
  71.  
  72. service strongswan restart
  73. service xl2tpd restart
  74.  
  75. cat > /usr/local/bin/start-vpn <<EOF
  76. #!/bin/bash
  77.  
  78. (service strongswan start ;
  79. sleep 2 ;
  80. service xl2tpd start) && (
  81.  
  82. ipsec up $VPN_CONNETCTION_NAME
  83. echo "c ${VPN_CONNETCTION_NAME}" > /var/run/xl2tpd/l2tp-control
  84. sleep 5
  85. #ip route add 10.0.0.0/24 dev ppp0
  86. )
  87. EOF
  88. chmod +x /usr/local/bin/start-vpn
  89.  
  90. cat > /usr/local/bin/stop-vpn <<EOF
  91. #!/bin/bash
  92.  
  93. (echo "d ${VPN_CONNETCTION_NAME}" > /var/run/xl2tpd/l2tp-control
  94. ipsec down $VPN_CONNETCTION_NAME) && (
  95. service xl2tpd stop ;
  96. service strongswan stop)
  97. EOF
  98. chmod +x /usr/local/bin/stop-vpn
  99.  
  100. echo "To start VPN type: start-vpn"
  101. echo "To stop VPN type: stop-vpn"
Add Comment
Please, Sign In to add comment