Pull to refresh

Настройка vpn wireguard на примере маршрутизатора openwrt в роли сервера и macos в роли клиента

Сервер OpenWrt


Установить пакет wireguard


Минимальная установка


opkg update
opkg install wireguard

Дополнительно можно установить модули для luci


opkg install luci-app-wireguard

Создать private и public ключи


wg genkey | tee wg.key | wg pubkey > wg.pub

Дополнительно можно сгенерировать preshared ключ


wg genpsk > wg.psk

Настроить сетевой интерфейс


Редактировать файл


vim /etc/config/network

Где Wireguard название интерфейса


config interface 'wireguard'
        option proto 'wireguard'
        option private_key '<PrivateKey>'
        option listen_port '1234'
        list addresses '10.8.0.1/24'

Настроить peer


Опция preshared_key не обязательная


config wireguard_wireguard
        option route_allowed_ips '1'
        option persistent_keepalive '25'
        option public_key '<PublicKey>'
        option preshared_key '<PresharedKey>'
        list allowed_ips '10.8.0.2/32'

Перезапустить сервис network


/etc/init.d/network restart

Настроить firewall


Редактировать файл


vim /etc/config/firewall

Открыть порт 1234


config rule
        option target 'ACCEPT'
        option src 'wan'
        option proto 'udp'
        option dest_port '1234'
        option name 'Allow-WireGuard'
    option family 'ipv4'

Занести интерфейс Wireguard в зону lan и включить опицию Masquerading


Без опции Masquerading на клиенте не будет доступен интернет и все что находиться за tap0 интерфейсом (в моем случае есть openvpn bridge с tap0 интерфейсом)


config zone
        option name 'lan'
        option network 'lan openvpn wireguard'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        option masq '1'

Перезапустить сервис firewall


/etc/init.d/firewall restart

Клиент MacOs


Установить приложение


Установить приложение WireGuard из App Store


Пример конфигурации


Опция PresharedKey зависит от настроек сервера


[Interface]
PrivateKey = <PrivateKey>
Address = 10.8.0.2/32
DNS = <ip>

[Peer]
PublicKey = <PublicKey>
PresharedKey = <PresharedKey>
AllowedIPs = 0.0.0.0/0
Endpoint = <ip>:1234
Tags:
Hubs:
You can’t comment this publication because its author is not yet a full member of the community. You will be able to contact the author only after he or she has been invited by someone in the community. Until then, author’s username will be hidden by an alias.