sudo apt update -y && sudo apt upgrade -y
sudo apt install linux-headers-$(uname -r) wireguard wireguard-dkms net-tools -yBashsudo nano /etc/wireguard/wg0.confBash[Interface]
Address = 10.10.0.1/24
SaveConfig = true
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADEConfsudo wg-quick up wg0Bashsudo wg show wg0Bashsudo systemctl enable wg-quick@wg0BashFor NAT to work, we need to enable IP forwarding. Open the /etc/sysctl.conf file and add or uncomment the following line
sudo nano /etc/sysctl.confBashnet.ipv4.ip_forward=1
sudo sysctl -pBashwg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickeyBashsudo nano /etc/wireguard/wg0.confBashFor setting up IP Port forwarding, Add the subnet in AllowedIPs in wg0.conf and also:
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
PostUp = /etc/wireguard/port-up.sh
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; iptables -t nat -D POSTROUTING -o wg0 -j MASQUERADE
PostDown = /etc/wireguard/port-down.shConfIn the port-up.sh
sudo iptables -t nat -A PREROUTING -p tcp --dport 5060 -j DNAT --to-destination 10.30.30.14:5060Bash