vpn01% sudo chmod 600 /etc/wireguard/wg0.conf
vpn01% sudo wg-quick up wg0
[#] ip link add wg0 type wireguard[#] wg setconf wg0 /dev/fd/63[#] ip -4 address add 10.0.1.11/24 dev wg0[#] ip link set mtu 1440 up dev wg0
設定の確認
wg showとwg showconfで現在の設定状況を確認できます。
1
2
3
4
5
6
7
8
9
10
vpn01% sudo wg show
interface: wg0
public key: +BBEy1MjXwXtaIXNodhGTSKAA+83U0F9JYj5/v9PZFk=
private key: (hidden)
listening port: 8172
peer: BAvxl5NXctUX7cJc1kjEG306846fIMFERsRdWazhGis=
preshared key: (hidden)
allowed ips: 10.0.1.21/32
persistent keepalive: every 25 seconds
vpn01% ip a s dev wg0
4: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1440 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.0.1.11/24 scope global wg0
valid_lft forever preferred_lft forever
vpn01% sudo chmod 600 /etc/wireguard/wg0.conf
vpn01% sudo wg-quick up wg0
[#] ip link add wg0 type wireguard[#] wg setconf wg0 /dev/fd/63[#] ip -4 address add 10.0.1.21/24 dev wg0[#] ip link set mtu 1440 up dev wg0
設定の確認
vpn01と同様に設定を確認します。
うまく設定できていれば、この時点で通信できるはずです。
1
2
3
4
5
6
7
8
9
10
11
12
13
vpn02% sudo wg show
interface: wg0
public key: BAvxl5NXctUX7cJc1kjEG306846fIMFERsRdWazhGis=
private key: (hidden)
listening port: 44507
peer: +BBEy1MjXwXtaIXNodhGTSKAA+83U0F9JYj5/v9PZFk=
preshared key: (hidden)
endpoint: 192.168.122.24:8172
allowed ips: 10.0.1.0/24
latest handshake: 1 minute, 40 seconds ago
transfer: 344 B received, 488 B sent
persistent keepalive: every 25 seconds
vpn02% ip a s dev wg0
4: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1440 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.0.1.21/24 scope global wg0
valid_lft forever preferred_lft forever
疎通確認
相互にpingして確認します。
1
2
3
4
5
6
7
8
9
vpn01% ping -c 3 10.0.1.21
PING 10.0.1.21 (10.0.1.21): 56 data bytes
64 bytes from 10.0.1.21: seq=0 ttl=64 time=1.327 ms
64 bytes from 10.0.1.21: seq=1 ttl=64 time=1.334 ms
64 bytes from 10.0.1.21: seq=2 ttl=64 time=1.311 ms
--- 10.0.1.21 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 1.311/1.324/1.334 ms
1
2
3
4
5
6
7
8
9
vpn02% ping -c 3 10.0.1.11
PING 10.0.1.11 (10.0.1.11): 56 data bytes
64 bytes from 10.0.1.11: seq=0 ttl=64 time=1.131 ms
64 bytes from 10.0.1.11: seq=1 ttl=64 time=0.995 ms
64 bytes from 10.0.1.11: seq=2 ttl=64 time=1.505 ms
--- 10.0.1.11 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.995/1.210/1.505 ms
wg0インタフェースに対してtcpdumpするとより分かりやすいかもしれません。
1
2
3
4
5
6
7
8
9
vpn02% sudo tcpdump -i wg0
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on wg0, link-type RAW (Raw IP), snapshot length 262144 bytes
23:18:05.762153 IP 10.0.1.11 > 10.0.1.21: ICMP echo request, id 2138, seq 0, length 64
23:18:05.762252 IP 10.0.1.21 > 10.0.1.11: ICMP echo reply, id 2138, seq 0, length 64
23:18:06.762723 IP 10.0.1.11 > 10.0.1.21: ICMP echo request, id 2138, seq 1, length 64
23:18:06.762827 IP 10.0.1.21 > 10.0.1.11: ICMP echo reply, id 2138, seq 1, length 64
23:18:07.763206 IP 10.0.1.11 > 10.0.1.21: ICMP echo request, id 2138, seq 2, length 64
23:18:07.763303 IP 10.0.1.21 > 10.0.1.11: ICMP echo reply, id 2138, seq 2, length 64
うまく繋がらない時は?
IPアドレスやAllowedIPs、鍵の設定に誤りがないか確認
ping: sendto: No error informationと出たらこれらを間違えている可能性大