Last active
September 6, 2017 10:35
-
-
Save imlonghao/c40ab21017fd2427ca394a5fce99409a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable-wireguard.list | |
printf 'Package: *\nPin: release a=unstable\nPin-Priority: 150\n' > /etc/apt/preferences.d/limit-unstable | |
apt update | |
apt install wireguard-dkms wireguard-tools -y | |
apt dist-upgrade -y | |
cat > /etc/rc.local << EOF | |
#!/bin/sh | |
/etc/wg.sh | |
exit 0 | |
EOF | |
cat > /etc/wg.sh << EOF | |
#!/bin/sh | |
EOF | |
chmod +x /etc/rc.local | |
chmod +x /etc/wg.sh | |
systemctl start rc.local | |
wget https://gist.githubusercontent.com/imlonghao/c40ab21017fd2427ca394a5fce99409a/raw/a029a33afd492589df7f10e9378a9485023074d8/wg.sh | |
chmod +x wg.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p "PSK: [M]aster / [S]lave / [N]one: " type | |
if [ "$type" == "M" ] || [ "$type" == "m" ] | |
then | |
psk=$(wg genpsk) | |
echo "PSK: $psk" | |
elif [ "$type" == "S" ] || [ "$type" == "s" ] | |
then | |
read -p "PSK: " psk | |
elif [ "$type" == "N" ] || [ "$type" == "n" ] | |
then | |
echo "No PSK, skipping..." | |
else | |
echo "Wrong input. Valid values: M|m|S|s|N|n" | |
exit 1 | |
fi | |
read -p "IPv[4] / IPv[6] / [H]ostname: " inet | |
if [ "$inet" == "4" ] || [ "$inet" == "H" ] || [ "$inet" == "h" ] | |
then | |
endpoint=$endpoint | |
elif [ "$inet" == "6" ] | |
then | |
endpoint="[$endpoint]" | |
else | |
echo "Wrong input. Valid values: 4|6|H|h" | |
exit 1 | |
fi | |
read -p "Endpoint: " endpoint | |
read -p "Local Port: " lport | |
read -p "Peer's Port: " rport | |
privkey=$(wg genkey) | |
pubkey=$(echo "$privkey" | wg pubkey) | |
read -p "Desired Interface Name: " interface | |
read -p "Tunnel IPv6: " laddr6 | |
echo "Pubkey: $pubkey" | |
read -p "Peer's Pubkey: " ppub | |
wgconfig=/etc/wireguard/$interface.conf | |
cat > $wgconfig << EOF | |
[Interface] | |
ListenPort = $lport | |
PrivateKey = $privkey | |
[Peer] | |
EOF | |
if [ "$type" == "M" ] || [ "$type" == "m" ] || [ "$type" == "S" ] || [ "$type" == "s" ] | |
then | |
cat >> $wgconfig << EOF | |
PresharedKey = $psk | |
EOF | |
fi | |
cat >> $wgconfig << EOF | |
PublicKey = $ppub | |
AllowedIPs = 0.0.0.0/0, ::/0 | |
Endpoint = $endpoint:$rport | |
EOF | |
cat >> /etc/wg.sh << EOF | |
ip link add dev $interface type wireguard | |
wg setconf $interface /etc/wireguard/$interface.conf | |
ip addr add $laddr6 dev $interface | |
ip link set $interface up | |
EOF | |
ip link add dev $interface type wireguard | |
wg setconf $interface /etc/wireguard/$interface.conf | |
ip addr add $laddr6 dev $interface | |
ip link set $interface up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment