LINUX.ORG.RU
ФорумAdmin

Проброс траффика между интерфейсами wg

 , ,


0

1

Всем привет.

Есть сервер на Debian 10, на нём настроны два wg интерфейса (один сервер, другой клиент):

WG server

root@0x4:/etc/wireguard# cat wg0s.conf 
[Interface]
Address = 10.0.0.1/24
SaveConfig = false
PostUp = iptables -A FORWARD -i wg0s -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0s -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0s -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i wg0s -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
ListenPort = 51820
PrivateKey = <private_key>

[Peer]
PublicKey = <public_key>
AllowedIPs = 10.0.0.2/32
Endpoint = <ep_ip>:32451

[Peer]
PublicKey = <public_key>
AllowedIPs = 10.0.0.3/32
Endpoint = <ep_ip>:61734

WG client

root@0x4:~# cat /etc/wireguard/rwg0.conf 
[Interface]
PrivateKey = <private_key>
Address = 192.168.204.203/24

[Peer]
PublicKey = <public_key>
AllowedIPs = 192.168.204.0/24
Endpoint = <ep_ip>:53684
PersistentKeepalive = 25

Есть другой клиент, который коннектится к этому серверу, имеет IP 10.0.0.3/24. Нужно настроить форвард траффика с этого клиента в подсеть 192.168.204.0/24 через Debian сервер. Пытался мучить iptables, но не выходит? траффик не идёт. Что здесь не так? Чего нужно подкрутить?


Ответ на: комментарий от zolden

Сейчас я поменял конфигурацию, засунул все в один файла на сервере, чтобы не плодить интерфейсы:

Debian сервер

[Interface]
PrivateKey = <priv key>
Address = 192.168.204.203/24
ListenPort = 51820

# PostUp = iptables -A FORWARD -i rwg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i rwg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# PostDown = iptables -D FORWARD -i rwg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i rwg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
 
[Peer]
PublicKey = <pub key>
AllowedIPs = 192.168.204.0/24
Endpoint = <endpoint ip>:51820
PersistentKeepalive = 25

[Peer]
PublicKey = <pub key>
AllowedIPs = 10.0.0.3/32

С хоста 10.0.0.3 могу пинговать хост 192.168.204.1, но не могу другие этой подсети. С сервера на другие хосты проходят замечательно:

root@0x4:/etc/wireguard# ping 192.168.204.23 -c1
PING 192.168.204.23 (192.168.204.23) 56(84) bytes of data.
64 bytes from 192.168.204.23: icmp_seq=1 ttl=63 time=106 ms

--- 192.168.204.23 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 106.234/106.234/106.234/0.000 ms
root@0x4:/etc/wireguard#

и

blackhorse ~ # ping 192.168.204.23 -c 1
PING 192.168.204.23 (192.168.204.23) 56(84) bytes of data.

--- 192.168.204.23 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

Хост 10.0.0.4:

blackhorse ~ # ip -4 -c -br a
lo               UNKNOWN        127.0.0.1/8 
bridge           UP             192.168.10.1/24 
rwg-vps          UNKNOWN        10.0.0.3/24

blackhorse ~ # ip r
default via 192.168.10.17 dev bridge proto static 
10.0.0.0/24 dev rwg-vps proto kernel scope link src 10.0.0.3 
192.168.10.0/24 dev bridge proto kernel scope link src 192.168.10.1 
192.168.204.0/24 dev rwg-vps scope link

blackhorse ~ # ip ru
0:	from all lookup local
32766:	from all lookup main
32767:	from all lookup default

Debian server:

root@0x4:/etc/wireguard# ip -4 -c -br a
lo               UNKNOWN        127.0.0.1/8 
eth0             UP             31.131.26.89/24 
rwg0             UNKNOWN        192.168.204.203/24

root@0x4:/etc/wireguard# ip r
default via 31.131.26.1 dev eth0 onlink 
10.0.0.3 dev rwg0 scope link 
<private>/24 dev eth0 proto kernel scope link src <private> 
192.168.204.0/24 dev rwg0 proto kernel scope link src 192.168.204.203 
root@0x4:/etc/wireguard#

ubik ()
Ответ на: комментарий от zolden
root@0x4:/etc/wireguard# iptables-save
# Generated by xtables-save v1.8.2 on Tue Aug  4 14:00:53 2020
*filter
:INPUT DROP [864797:40823047]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [20673:1249865]
:ufw-before-logging-input - [0:0]
:ufw-before-logging-output - [0:0]
:ufw-before-logging-forward - [0:0]
:ufw-before-input - [0:0]
:ufw-before-output - [0:0]
:ufw-before-forward - [0:0]
:ufw-after-input - [0:0]
:ufw-after-output - [0:0]
:ufw-after-forward - [0:0]
:ufw-after-logging-input - [0:0]
:ufw-after-logging-output - [0:0]
:ufw-after-logging-forward - [0:0]
:ufw-reject-input - [0:0]
:ufw-reject-output - [0:0]
:ufw-reject-forward - [0:0]
:ufw-track-input - [0:0]
:ufw-track-output - [0:0]
:ufw-track-forward - [0:0]
:ufw-logging-deny - [0:0]
:ufw-logging-allow - [0:0]
:ufw-skip-to-policy-input - [0:0]
:ufw-skip-to-policy-output - [0:0]
:ufw-skip-to-policy-forward - [0:0]
:ufw-not-local - [0:0]
:ufw-user-input - [0:0]
:ufw-user-output - [0:0]
:ufw-user-forward - [0:0]
:ufw-user-logging-input - [0:0]
:ufw-user-logging-output - [0:0]
:ufw-user-logging-forward - [0:0]
:ufw-user-limit - [0:0]
:ufw-user-limit-accept - [0:0]
-A INPUT -j ufw-before-logging-input
-A INPUT -j ufw-before-input
-A INPUT -j ufw-after-input
-A INPUT -j ufw-after-logging-input
-A INPUT -j ufw-reject-input
-A INPUT -j ufw-track-input
-A FORWARD -j ufw-before-logging-forward
-A FORWARD -j ufw-before-forward
-A FORWARD -j ufw-after-forward
-A FORWARD -j ufw-after-logging-forward
-A FORWARD -j ufw-reject-forward
-A FORWARD -j ufw-track-forward
-A FORWARD -i wg0s -j ACCEPT
-A FORWARD -i rwg0 -j ACCEPT
-A OUTPUT -j ufw-before-logging-output
-A OUTPUT -j ufw-before-output
-A OUTPUT -j ufw-after-output
-A OUTPUT -j ufw-after-logging-output
-A OUTPUT -j ufw-reject-output
-A OUTPUT -j ufw-track-output
-A ufw-before-input -i lo -j ACCEPT
-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny
-A ufw-before-input -m conntrack --ctstate INVALID -j DROP
-A ufw-before-input -p icmp -m icmp --icmp-type 3 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 4 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 12 -j ACCEPT
-A ufw-before-input -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A ufw-before-input -p udp -m udp --sport 67 --dport 68 -j ACCEPT
-A ufw-before-input -j ufw-not-local
-A ufw-before-input -d 224.0.0.251/32 -p udp -m udp --dport 5353 -j ACCEPT
-A ufw-before-input -d 239.255.255.250/32 -p udp -m udp --dport 1900 -j ACCEPT
-A ufw-before-input -j ufw-user-input
-A ufw-before-output -o lo -j ACCEPT
-A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A ufw-before-output -j ufw-user-output
-A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 3 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 4 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 12 -j ACCEPT
-A ufw-before-forward -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A ufw-before-forward -j ufw-user-forward
-A ufw-after-input -p udp -m udp --dport 137 -j ufw-skip-to-policy-input
-A ufw-after-input -p udp -m udp --dport 138 -j ufw-skip-to-policy-input
-A ufw-after-input -p tcp -m tcp --dport 139 -j ufw-skip-to-policy-input
-A ufw-after-input -p tcp -m tcp --dport 445 -j ufw-skip-to-policy-input
-A ufw-after-input -p udp -m udp --dport 67 -j ufw-skip-to-policy-input
-A ufw-after-input -p udp -m udp --dport 68 -j ufw-skip-to-policy-input
-A ufw-after-input -m addrtype --dst-type BROADCAST -j ufw-skip-to-policy-input
-A ufw-after-logging-input -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW BLOCK] "
-A ufw-after-logging-forward -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW BLOCK] "
-A ufw-track-output -p tcp -m conntrack --ctstate NEW -j ACCEPT
-A ufw-track-output -p udp -m conntrack --ctstate NEW -j ACCEPT
-A ufw-logging-deny -m conntrack --ctstate INVALID -m limit --limit 3/min --limit-burst 10 -j RETURN
-A ufw-logging-deny -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW BLOCK] "
-A ufw-logging-allow -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix "[UFW ALLOW] "
-A ufw-skip-to-policy-input -j DROP
-A ufw-skip-to-policy-output -j ACCEPT
-A ufw-skip-to-policy-forward -j DROP
-A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN
-A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN
-A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN
-A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny
-A ufw-not-local -j DROP
-A ufw-user-input -p udp -m udp --dport 1194 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 22 -m comment --comment "\'dapp_OpenSSH\'" -j ACCEPT
-A ufw-user-input -p udp -m udp --dport 51820 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 80 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 443 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 22 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 5000 -j REJECT --reject-with tcp-reset
-A ufw-user-input -p udp -m udp --dport 5000 -j REJECT --reject-with icmp-port-unreachable
-A ufw-user-input -p tcp -m tcp --dport 993 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 465 -j ACCEPT
-A ufw-user-input -p tcp -m tcp --dport 25 -j ACCEPT
-A ufw-user-forward -s 10.0.0.0/24 -d 192.168.204.0/24 -i wg0s -o rwg0 -j ACCEPT
-A ufw-user-forward -s 192.168.204.0/24 -d 10.0.0.0/24 -i rwg0 -o wg0s -j ACCEPT
-A ufw-user-limit -m limit --limit 3/min -j LOG --log-prefix "[UFW LIMIT BLOCK] "
-A ufw-user-limit -j REJECT --reject-with icmp-port-unreachable
-A ufw-user-limit-accept -j ACCEPT
COMMIT
# Completed on Tue Aug  4 14:00:53 2020
# Generated by xtables-save v1.8.2 on Tue Aug  4 14:00:53 2020
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [311123:22293542]
:OUTPUT ACCEPT [0:0]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Tue Aug  4 14:00:53 2020
root@0x4:/etc/wireguard#

Другие хосты из 192.168.204.0 подсети показать не могу, т.к. к ним нет доступа.

ubik ()
Ответ на: комментарий от ubik

Да на какой вопрос?

На той стороне, куда коннектится ваш Debian 10 сервер, прописан маршрут к 10.0.0.3/32 и он занесён в AllowedIPs? Или SNAT настраивайте, если вы к тем настройкам доступа не имеете.

mky ★★★★★ ()