https://songer.pro/how-to-install-wireguard-on-ubuntu-20-04/
' e1 Z% j4 D* Y- R2 z% N! D
https://linuxize.com/post/how-to-set-up-wireguard-vpn-on-centos-8/ 这是一个学习LINUX的好网站
7 h" Y2 x! [- P' D, q0 n/ Q
* X7 B. ~7 i- x$ `/ b ~$ l1 ^0 m6 T6 }
centos7下预置的yum源应用安装及更新比较慢,有时还掉链子,更换到国内的源比较省心,这里以阿里源为例。 进入到源文件目录 cd /etc/yum.repos.d 备份旧的配置文件 mv CentOS-Base.repo CentOS-Base.repo.bak 下载阿里源的文件 清理缓存 yum clean all 重新生成缓存 yum makecache
2 W% `0 w. q0 K, y Update and Upgrade Ubuntusudo apt-get update && sudo apt-get upgrade -yInstall Wireguardsudo apt-get install wireguardOpen the system variables file for edit. sudo nano /etc/sysctl.confThen uncomment the following line by removing the # at the beginning of the line. net.ipv4.ip_forward=1Apply sudo sysctl -p Install and Configure UFW# Install UFWsudo apt install ufw# Firewall Rulessudo ufw allow sshsudo ufw allow 51820/udp# Enable Firewallsudo ufw enable#Check UFW Statussudo ufw status Generating private and public keys and Configure# Change Directorycd /etc/wireguard# Set Permissionsumask 077# Generate a new key pair with the command belowwg genkey | tee privatekey | wg pubkey > publickeyGenerate server config# Create new config filesudo nano /etc/wireguard/wg0.conf[Interface]PrivateKey = <contents-of-server-privatekey>Address = 10.0.0.1/24PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEPostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADEListenPort = 51820[Peer]PublicKey = <contents-of-client-publickey>AllowedIPs = 10.0.0.2/32sudo cat /etc/wireguard/publickeysudo cat /etc/wireguard/privatekeyStart Wireguard wg-quick up wg0Check Wireguard Config wg showEnable Automatic Start systemctl enable wg-quick@wg0Update Server sudo apt-get update && sudo apt-get upgrade -y Client configuration
) d8 L8 U) O- J6 f8 h0 X" y. CCreate new Config file on Client Device sudo nano /etc/wireguard/wg0.confRemember to set the client private key and server public key to their corresponding places and also include your WireGuard server’s public IP address. [Interface]Address = 10.0.0.2/32PrivateKey = <contents-of-client-privatekey>DNS = 1.1.1.1[Peer]PublicKey = <contents-of-server-publickey>Endpoint = <server-public-ip>:51820AllowedIPs = 0.0.0.0/0, ::/0Note that setting AllowedIPs to 0.0.0.0/0, ::/0 will forward all traffic over the WireGuard VPN connection.Start the connection with the command below. sudo wg-quick up wg0To Disconnect sudo wg-quick down wg0sudo systemctl stop wg-quick@wg0 |