WireGuard - настройка
Установка WireGuard на Centos/RockyLinux/RHEL
Ссылка на скачивание под разные платформы: https://www.wireguard.com/install/
Обновляем источники и подключаем WireGuard репозиторий (Centos 8)
yum update -y yum install epel-release -y
yum install 'dnf-command(config-manager)' -y yum config-manager --set-enabled PowerTools -y yum copr enable jdoss/wireguard -y yum install wireguard-dkms wireguard-tools -y
Обновляем источники и подключаем WireGuard репозиторий (Centos 7)
yum update -y yum install epel-release https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm -y yum install yum-plugin-elrepo -y yum install kmod-wireguard wireguard-tools -y
Проверка что модуль установлен, возможно понадобится перезагрузка.
modinfo wireguard
Возможно придется переустановить пакеты и сделать проверку еще раз.
yum reinstall wireguard-dkms wireguard-tools
Настройка после установки
mkdir -v /etc/wireguard/ touch /etc/wireguard/wg0.conf chmod 700 /etc/wireguard/wg0.conf
Генерируем ключи
cd /etc/wireguard/ wg genkey | tee server.privatekey | wg pubkey > server.publickey
Конфигурационный файл wg0.conf
[Interface] #-- VPN server private IP address pool -- Address = 192.168.5.1/24 #-- VPN server UDP port -- ListenPort = 31194 #-- VPN server's private key i.e. /etc/wireguard/server.privatekey -- PrivateKey = ARGf2OPRhypgRZ8t/k4/fcfcvDedB12HgceW1iQJj+9mc== #-- Save and update this config file when a new peer (vpn client) added -- SaveConfig = true [Peer] #-- Client-1 Public key -- PublicKey = QRG2OPhypRZ8t/k2/fcfcvDedB12HbgceW1iQJj+9Qc= AllowedIPs = 192.168.100.2/32
[Peer] #-- Client-2 Public key -- PublicKey = Hdepww28dhahgdwTqOjh3u3ddB12HbgceW1iQJj+9Qc= AllowedIPs = 192.168.100.3/32
Настраиваем правила фаерволла: iptables
#-- MASQUARADE:: Masquarade WireGuard clients (nat)-- -A POSTROUTING -s 192.168.100.0/24 -o ens3 -j MASQUERADE #-- INPUT:: WireGuard Allow Input (filter) -- -A INPUT -m state --state NEW -m udp -p udp --dport 31194 -j ACCEPT #-- FORWARD:: Allow forward WireGuard client (filter) -- -A FORWARD -m state --state NEW -s 192.168.100.0/24 -j ACCEPT
Создаем правила для параметров системы: 99-wireguard.conf
touch /etc/sysctl.d/99-wireguard.conf ## Turn on bbr ## net.core.default_qdisc = fq net.ipv4.tcp_congestion_control = bbr ## for IPv4 ## net.ipv4.ip_forward = 1 ## Turn on basic protection/security ## net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.all.rp_filter = 1 net.ipv4.tcp_syncookies = 1 ## for IPv6 - uncomment the following line ## #net.ipv6.conf.all.forwarding = 1
Применяем правила:
sysctl -p /etc/sysctl.d/99-wireguard.conf
Добавляем в автозагрузку, запускаем и проверяем состояние
systemctl enable wg-quick@wg0 systemctl start wg-quick@wg0 systemctl status wg-quick@wg0