port 1194
proto udp
dev tun
ca ca.crt
cert rdv-strasbourg.crt
key rdv-strasbourg.key # This file should be kept secret
dh dh.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist /var/log/openvpn/ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
client-to-client
keepalive 10 120
tls-auth ta.key 0 # This file is secret
cipher AES-256-CBC
auth SHA256
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn/openvpn-status.log
verb 3
explicit-exit-notify 1%
*nat
# :PREROUTING ACCEPT [0:0]
# :INPUT ACCEPT [0:0]
# :OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
-A OUTPUT -o tun+ -j ACCEPT
COMMIT
*filter
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -j ACCEPT
# Openvpn
-A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT
-A INPUT -i tun+ -j ACCEPT
-A FORWARD -i tun+ -j ACCEPT
-A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -o tun+ -j ACCEPT
-A INPUT -j REJECT
-A FORWARD -j REJECT
--policy INPUT DROP
--policy FORWARD DROP
--policy OUTPUT ACCEPT
COMMIT
sudo ifconfig en0 down
sudo route -n flush
sudo ifconfig en0 up
Итак, клиент (MacOS) устанавливает VPN-соединение с сервером (Linux), на котором крутятся DB-сервисы. По какому IP-адресу Вы обращаетесь к СУБД - по второму (LAN) или по третьему (VPN)?
-A INPUT -s 78.XX.XX.XX -p tcp --dport 27017 -j ACCEPT
~ » traceroute 78.XX.XX.19
traceroute to 78.XX.XX.19 (78.XX.XX.19), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 1.746 ms 0.941 ms 1.047 ms
2 85.XX.XX.1 (85.XX.XX.1) 2.779 ms 2.110 ms 2.622 ms
3 * * *
traceroute ya.ru
traceroute to ya.ru (87.250.250.242), 64 hops max, 52 byte packets
1 10.8.0.1 (10.8.0.1) 49.248 ms 48.095 ms 48.284 ms
2 static.1.XX.XX.78.clients.your-server.de (78.XX.XX.1) 49.483 ms 49.439 ms 50.649 ms
3 core24.fsn1.hetzner.com (213.239.229.69) 48.905 ms
core23.fsn1.hetzner.com (213.239.229.65) 50.174 ms
core24.fsn1.hetzner.com (213.239.229.69) 48.273 ms
4 core4.fra.hetzner.com (213.239.229.73) 125.631 ms
core1.fra.hetzner.com (213.239.229.77) 53.272 ms 53.503 ms
5 core8.fra.hetzner.com (213.239.245.126) 53.957 ms 55.444 ms
core8.fra.hetzner.com (213.239.245.86) 53.646 ms
6 fra1-b1-xe-0-1-3.yndx.net (5.45.200.40) 53.449 ms 53.983 ms 53.648 ms
7 ya.ru (87.250.250.242) 78.497 ms 78.351 ms 77.743 ms
netstat -nr
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
0/1 10.8.0.5 UGSc 103 21 utun2
default 192.168.1.1 UGSc 1 0 en0
10.8.0.1/32 10.8.0.5 UGSc 0 0 utun2
10.8.0.5 10.8.0.6 UHr 26 0 utun2
78.XX.XX.19/32 192.168.1.1 UGSc 4 34 en0
127 127.0.0.1 UCS 0 6 lo0
127.0.0.1 127.0.0.1 UH 36 8748657 lo0
128.0/1 10.8.0.5 UGSc 6 0 utun2
169.254 link#7 UCS 1 0 en0 !
192.168.1 link#7 UCS 5 0 en0 !
192.168.1.1/32 link#7 UCS 1 0 en0 !
192.168.1.1 a8:5e:45:29:2:78 UHLWIir 4 409 en0 1102
192.168.1.7 0:11:32:48:bf:e7 UHLWIi 4 61253 en0 318
192.168.1.11 0:15:99:a6:a3:10 UHLWI 0 0 en0 1068
192.168.1.137/32 link#7 UCS 1 0 en0 !
192.168.1.137 28:cf:e9:18:7:13 UHLWI 0 4 lo0
192.168.1.153 f0:98:9d:17:99:13 UHLWI 0 12 en0 83
192.168.1.167 70:70:d:14:48:12 UHLWIi 2 1334 en0 318
192.168.1.255 ff:ff:ff:ff:ff:ff UHLWbI 0 5 en0 !
224.0.0/4 link#7 UmCS 2 0 en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 0 en0
224.6.7.8 1:0:5e:6:7:8 UHmLWI 0 0 en0
255.255.255.255/32 link#7 UCS 0 0 en0 !
Internet6:
Destination Gateway Flags Netif Expire
default fe80::%utun0 UGcI utun0
default fe80::%utun1 UGcI utun1
::1 ::1 UHL lo0
fe80::%lo0/64 fe80::1%lo0 UcI lo0
fe80::1%lo0 link#1 UHLI lo0
fe80::%awdl0/64 link#11 UCI awdl0
fe80::d0ba:68ff:fe4c:2af5%awdl0 d2:ba:68:4c:2a:f5 UHLI lo0
fe80::%utun0/64 fe80::d1a9:650d:77ab:b806%utun0 UcI utun0
fe80::d1a9:650d:77ab:b806%utun0 link#13 UHLI lo0
fe80::%utun1/64 fe80::1c41:b570:cae1:4d85%utun1 UcI utun1
fe80::1c41:b570:cae1:4d85%utun1 link#14 UHLI lo0
ff01::%lo0/32 ::1 UmCI lo0
ff01::%awdl0/32 link#11 UmCI awdl0
ff01::%utun0/32 fe80::d1a9:650d:77ab:b806%utun0 UmCI utun0
ff01::%utun1/32 fe80::1c41:b570:cae1:4d85%utun1 UmCI utun1
ff02::%lo0/32 ::1 UmCI lo0
ff02::%awdl0/32 link#11 UmCI awdl0
ff02::%utun0/32 fe80::d1a9:650d:77ab:b806%utun0 UmCI utun0
ff02::%utun1/32 fe80::1c41:b570:cae1:4d85%utun1 UmCI utun1
traceroute to 78.XX.XX.19 (78.XX.XX.19), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 2.111 ms 0.960 ms 1.039 ms
2 85.XX.XX.1 (85.249.40.1) 2.187 ms 2.376 ms 2.159 ms
3 * * *
traceroute to ya.ru (87.250.250.242), 64 hops max, 52 byte packets
1 10.8.0.1 (10.8.0.1) 59.271 ms 59.733 ms 59.158 ms
2 51.XX.XX.1 (51.XX.XX.1) 59.658 ms 59.633 ms 59.031 ms
...
netstat -nr vsokolov@Vitalys-MacBook-Pro
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
0/1 10.8.0.5 UGSc 85 42 utun2
default 192.168.1.1 UGSc 0 0 en0
10.8.0.1/32 10.8.0.5 UGSc 0 0 utun2
10.8.0.5 10.8.0.6 UHr 16 0 utun2
51.XX.XX.80/32 192.168.1.1 UGSc 1 0 en0
78.XX.XX.19/32 192.168.1.1 UGSc 1 34 en0
127 127.0.0.1 UCS 0 6 lo0
127.0.0.1 127.0.0.1 UH 36 8876745 lo0
128.0/1 10.8.0.5 UGSc 4 0 utun2
169.254 link#7 UCS 1 0 en0 !
192.168.1 link#7 UCS 5 0 en0 !
192.168.1.1/32 link#7 UCS 1 0 en0 !
192.168.1.1 a8:5e:45:29:2:78 UHLWIir 6 474 en0 1118
192.168.1.7 0:11:32:48:bf:e7 UHLWIi 4 156438 en0 1166
192.168.1.11 0:15:99:a6:a3:10 UHLWI 0 0 en0 1160
192.168.1.100 98:1:a7:10:d6:5 UHLWI 0 2 en0 932
192.168.1.106 54:26:96:d1:f4:c7 UHLWI 0 0 en0 755
192.168.1.137/32 link#7 UCS 1 0 en0 !
192.168.1.137 28:cf:e9:18:7:13 UHLWI 0 6 lo0
192.168.1.167 70:70:d:14:48:12 UHLWIi 2 227 en0 933
224.0.0/4 link#7 UmCS 2 0 en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 0 en0
224.6.7.8 1:0:5e:6:7:8 UHmLWI 0 0 en0
255.255.255.255/32 link#7 UCS 0 0 en0 !
Internet6:
...
sudo ifconfig en0 down && sudo route -n flush && sudo ifconfig en0 up
78.XX.XX.19 192.168.1.1 done
route: write to routing socket: No such process
got only -1 for rlen
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.1.1 UGSc 115 0 en0
127 127.0.0.1 UCS 0 6 lo0
127.0.0.1 127.0.0.1 UH 36 8883209 lo0
169.254 link#7 UCS 1 0 en0 !
192.168.1 link#7 UCS 4 0 en0 !
192.168.1.1/32 link#7 UCS 1 0 en0 !
192.168.1.1 a8:5e:45:29:2:78 UHLWIir 34 56 en0 1187
192.168.1.7 0:11:32:48:bf:e7 UHLWIi 3 449 en0 1176
192.168.1.11 0:15:99:a6:a3:10 UHLWI 0 0 en0 1198
192.168.1.137/32 link#7 UCS 0 0 en0 !
192.168.1.167 70:70:d:14:48:12 UHLWIi 2 11 en0 1148
192.168.1.255 ff:ff:ff:ff:ff:ff UHLWbI 0 6 en0 !
224.0.0/4 link#7 UmCS 2 0 en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 0 en0
224.6.7.8 1:0:5e:6:7:8 UHmLWI 0 0 en0
255.255.255.255/32 link#7 UCS 0 0 en0 !
Internet6:
...
traceroute to 78.XX.XX.19 (78.XX.XX.19), 64 hops max, 52 byte packets
1 10.8.0.1 (10.8.0.1) 64.342 ms 62.760 ms 63.825 ms
2 51.XX.XX.1 (51.XX.XX.1) 61.261 ms 64.956 ms 62.824 ms
3 192.168.143.254 (192.168.143.254) 62.720 ms 61.876 ms 64.577 ms
...
| sed s/81\.15\.211\./81.XX.YY./
Причём менять можно много адресов, задав много масок замены. Особенно актуально эта замена для провайдерского адреса сервера.~ » netstat -nr
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.1.1 UGSc 104 0 en0
127 127.0.0.1 UCS 0 0 lo0
127.0.0.1 127.0.0.1 UH 336 5257932 lo0
169.254 link#7 UCS 0 0 en0 !
192.168.1 link#7 UCS 0 0 en0 !
192.168.1.1/32 link#7 UCS 1 0 en0 !
192.168.1.1 a8:5e:45:29:2:78 UHLWIir 9 15 en0 1200
192.168.1.137/32 link#7 UCS 0 0 en0 !
224.0.0/4 link#7 UmCS 1 0 en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 0 en0
255.255.255.255/32 link#7 UCS 0 0 en0 !
~ » netstat -nr
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
0/1 10.8.0.5 UGSc 132 0 utun1
default 192.168.1.1 UGSc 7 0 en0
10.8.0.1/32 10.8.0.5 UGSc 0 0 utun1
10.8.0.5 10.8.0.6 UHr 20 0 utun1
<b>51.XX.XX.80/32 192.168.1.1 UGSc 1 0 en0</b>
127 127.0.0.1 UCS 0 0 lo0
127.0.0.1 127.0.0.1 UH 334 5304842 lo0
128.0/1 10.8.0.5 UGSc 6 0 utun1
169.254 link#7 UCS 0 0 en0 !
192.168.1 link#7 UCS 2 0 en0 !
192.168.1.1/32 link#7 UCS 1 0 en0 !
192.168.1.1 a8:5e:45:29:2:78 UHLWIir 4 61 en0 1179
192.168.1.7 0:11:32:48:bf:e7 UHLWIi 3 1636 en0 779
192.168.1.137/32 link#7 UCS 1 0 en0 !
192.168.1.137 28:cf:e9:18:7:13 UHLWI 0 1 lo0
192.168.1.167 70:70:d:14:48:12 UHLWIi 2 106 en0 773
224.0.0/4 link#7 UmCS 1 0 en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 0 en0
255.255.255.255/32 link#7 UCS 0 0 en0 !
1 10.8.0.1 (10.8.0.1) 62.132 ms 60.107 ms 58.605 ms
2 <b>51.XX.XX.1</b> (51.XX.XX.1) 58.053 ms 58.082 ms 58.230 ms
~ » netstat -nr
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
0/1 10.8.0.5 UGSc 94 0 utun1
default 192.168.1.1 UGSc 3 0 en0
10.8.0.1/32 10.8.0.5 UGSc 0 0 utun1
10.8.0.5 10.8.0.6 UHr 25 0 utun1
<b>51.ХХ.ХХ.80/32 192.168.1.1 UGSc 1 0 en0
78.ХХ.ХХ.19/32 192.168.1.1 UGSc 1 0 en0</b>
127 127.0.0.1 UCS 0 0 lo0
127.0.0.1 127.0.0.1 UH 341 5330412 lo0
128.0/1 10.8.0.5 UGSc 7 0 utun1
169.254 link#7 UCS 0 0 en0 !
192.168.1 link#7 UCS 3 0 en0 !
192.168.1.1/32 link#7 UCS 1 0 en0 !
192.168.1.1 a8:5e:45:29:2:78 UHLWIir 6 203 en0 1198
192.168.1.7 0:11:32:48:bf:e7 UHLWIi 3 2572 en0 547
192.168.1.100 link#7 UHLWI 0 1 en0 !
192.168.1.137/32 link#7 UCS 1 0 en0 !
192.168.1.137 28:cf:e9:18:7:13 UHLWI 0 4 lo0
192.168.1.167 70:70:d:14:48:12 UHLWIi 2 164 en0 541
224.0.0/4 link#7 UmCS 1 0 en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI 0 0 en0
255.255.255.255/32 link#7 UCS 0 0 en0 !
1 192.168.1.1 (192.168.1.1) 1.716 ms 1.156 ms 1.045 ms
2 <b>85.XX.XX.1</b> (85.XX.XX.1) 2.146 ms 2.824 ms 3.122 ms
Если MongoDB и PostgreSQL слушают провайдерский IP-адрес (принимают соединения на провайдерском IP-адресе) - то никакой VPN их не скроет от внешнего доступа
-A INPUT -s <ip> -p tcp --dport 27017 -j ACCEPT
,