skx / simple-vpn

A simple VPN allowing mesh-like communication between nodes, over websockets
BSD 3-Clause "New" or "Revised" License
284 stars 48 forks source link

Unable to assign client IP address from server side #23

Closed Aster-the-Med-Stu closed 4 years ago

Aster-the-Med-Stu commented 4 years ago

In server.cfg we should be able to give a client a specific IP, but it is ignored.

Server side:

key = [Redacted]
subnet = 203.0.113.0/24
tencent-hk-01 = 203.0.113.100

Client side:

vpn = ws://127.0.0.1:9000
key = [redacted]
name = tencent-hk-01

After this is the server log:

Sep 25 13:41:01 [Redacted] systemd[1]: Started simple-vpn server.
Sep 25 13:42:01 [Redacted] simple-vpn[683]: Connection from IP:127.0.0.1
Sep 25 13:42:01 [Redacted] simple-vpn[683]: Client 'tencent-hk-01' [IP:127.0.0.1] assigned 203.0.113.2
Sep 25 13:42:01 [Redacted] simple-vpn[683]: Updating each peer with the connected peers
Sep 25 13:42:01 [Redacted] simple-vpn[683]:         0: 203.0.113.1        vpn-server
Sep 25 13:42:01 [Redacted] simple-vpn[683]:         1: 203.0.113.2        tencent-hk-01
Sep 25 13:42:01 [Redacted] simple-vpn[683]: 2020/09/25 13:42:01 [203.0.113.2] Got command reply ID 1: true
Sep 25 13:42:01 [Redacted] simple-vpn[683]: 2020/09/25 13:42:01 [203.0.113.2] Got command reply ID 2: true

Client side log:

Sep 25 13:42:01 [Redacted] systemd[1]: Started simple-vpn client.
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Client IP is 203.0.113.2
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Running: 'ip link set dev tun1 up'
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Running: 'ip link set mtu 1280 dev tun1'
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Running: 'ip addr add 203.0.113.2/32 dev tun1'
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Running: 'ip route add 203.0.113.1 dev tun1'
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Running: 'ip route add 203.0.113.0/24 via 203.0.113.1'
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: 2020/09/25 13:42:01 Configured interface, the VPN is up!
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Preparing to update peer-list
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: Peer command is empty.
Sep 25 13:42:01 [Redacted] simple-vpn[1442]: 2020/09/25 13:42:01 [0] Got command reply ID 1: true

It seems that the server didn't send the proper IP.

Aster-the-Med-Stu commented 4 years ago

You might have noticed client it is connecting to localhost:9000. That's because the server didn't have the first address 203.0.113.1 assigned to itself, see issue #22

Aster-the-Med-Stu commented 4 years ago

My bad... The entry should begin with "host_" suffix...