Guest User

Untitled

a guest
Oct 12th, 2021
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Be sure to allow port 51280 ingress
  4. # Working on Ubuntu 20.04
  5. # You need to press enter after the script pauses
  6. # my bash is weak
  7.  
  8. set -e
  9.  
  10. sudo apt update
  11. sudo apt install -y linux-headers-$(uname -r)
  12. sudo apt install -y wireguard wireguard-dkms wireguard-tools
  13.  
  14. sudo sysctl -w net.ipv4.ip_forward=1
  15. #sudo sysctl -w net.ipv4.conf.all.src_valid_mark=1
  16.  
  17. serverPrivateKey=$(wg genkey)
  18. serverPublicKey=$(echo ${serverPrivateKey} | wg pubkey)
  19. psk=$(wg genpsk)
  20. clientPrivateKey=$(wg genkey)
  21. clientPublicKey=$(echo ${clientPrivateKey} | wg pubkey)
  22.  
  23. cat | sudo tee /etc/wireguard/wg0.conf > /dev/null << EOF
  24. # Server
  25. [Interface]
  26. PrivateKey = ${serverPrivateKey}
  27. Address = 10.8.0.1/24
  28. ListenPort = 51820
  29.  
  30. PostUp = iptables -I FORWARD -i %i -j ACCEPT; iptables -I FORWARD -o %i -j ACCEPT; iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
  31. PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
  32.  
  33. # Client: ${clientname} (${clientId})
  34. [Peer]
  35. PublicKey = ${clientPublicKey}
  36. PresharedKey = ${psk}
  37. AllowedIPs = 10.8.0.2/32
  38.  
  39. EOF
  40.  
  41.  
  42.  
  43. wg-quick up wg0
  44.  
  45.  
  46.  
  47. cat << EOF
  48. # Client
  49. [Interface]
  50. PrivateKey = ${clientPrivateKey}
  51. Address = 10.8.0.2/24
  52.  
  53. [Peer]
  54. PublicKey = ${serverPublicKey}
  55. PresharedKey = ${psk}
  56. AllowedIPs = 0.0.0.0/0, ::0
  57. Endpoint = $(curl icanhazip.com):51820
  58.  
  59. EOF
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment