Temat: OpenVPN połączenie między dwoma sieciami

Witam

Potrzebuję wykonać konfigurację VPN pomiędzy dwoma routerami WRT160NL, do tej pory skonfigurowałem:

WRT160NL-serwer, hostname Serafin:

root@Serafin:~$ ifconfig
br-lan          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
eth1            inet addr:192.168.12.185  Bcast:192.168.12.255  Mask:255.255.255.0
tun0            inet addr:10.0.1.1  P-t-P:10.0.1.2  Mask:255.255.255.255

root@Serafin:~$ cat /etc/openvpn/openvpn.conf
dev tun
port 1194
proto udp
keepalive 10 120

persist-key
persist-tun

mode server

server 10.0.1.0 255.255.255.0
ifconfig-pool-persist /tmp/ipp.txt

verb 3

tls-server
push "route 10.0.1.0 255.255.255.0"

client-to-client

#logowanie
log-append /tmp/log/openvpn.log
status /tmp/log/openvpn.status

#certyfikaty
dh /etc/ssl/dh1024.pem
ca /etc/ssl/cacert.pem
cert /etc/ssl/servercert.pem
key /etc/ssl/private/serverkey.pem_wp

root@Serafin:~$ cat /etc/config/firewall

config 'defaults'
        option 'syn_flood' '1'
        option 'input' 'ACCEPT'
        option 'output' 'ACCEPT'
        option 'forward' 'REJECT'
        option 'drop_invalid' '1'

config 'zone'
        option 'name' 'lan'
        option 'network' 'lan'
        option 'input' 'ACCEPT'
        option 'output' 'ACCEPT'
        option 'forward' 'REJECT'

config 'zone'
        option 'name' 'wan'
        option 'network' 'wan'
        option 'input' 'REJECT'
        option 'output' 'ACCEPT'
        option 'forward' 'REJECT'
        option 'masq' '1'
        option 'mtu_fix' '1'

config 'forwarding'
        option 'src' 'lan'
        option 'dest' 'wan'

config 'rule'
        option 'name' 'Allow-DHCP-Renew'
        option 'src' 'wan'
        option 'proto' 'udp'
        option 'dest_port' '68'
        option 'target' 'ACCEPT'
        option 'family' 'ipv4'

config 'rule'
        option 'name' 'Allow-Ping'
        option 'src' 'wan'
        option 'proto' 'icmp'
        option 'icmp_type' 'echo-request'
        option 'family' 'ipv4'
        option 'target' 'ACCEPT'

config 'rule'
        option 'name' 'Allow-DHCPv6'
        option 'src' 'wan'
        option 'proto' 'udp'
        option 'src_ip' 'fe80::/10'
        option 'src_port' '547'
        option 'dest_ip' 'fe80::/10'
        option 'dest_port' '546'
        option 'family' 'ipv6'
        option 'target' 'ACCEPT'

config 'rule'
        option 'name' 'Allow-ICMPv6-Input'
        option 'src' 'wan'
        option 'proto' 'icmp'
        list 'icmp_type' 'echo-request'
        list 'icmp_type' 'destination-unreachable'
        list 'icmp_type' 'packet-too-big'
        list 'icmp_type' 'time-exceeded'
        list 'icmp_type' 'bad-header'
        list 'icmp_type' 'unknown-header-type'
        list 'icmp_type' 'router-solicitation'
        list 'icmp_type' 'neighbour-solicitation'
        option 'limit' '1000/sec'
        option 'family' 'ipv6'
        option 'target' 'ACCEPT'

config 'rule'
        option 'name' 'Allow-ICMPv6-Forward'
        option 'src' 'wan'
        option 'dest' '*'
        option 'proto' 'icmp'
        list 'icmp_type' 'echo-request'
        list 'icmp_type' 'destination-unreachable'
        list 'icmp_type' 'packet-too-big'
        list 'icmp_type' 'time-exceeded'
        list 'icmp_type' 'bad-header'
        list 'icmp_type' 'unknown-header-type'
        option 'limit' '1000/sec'
        option 'family' 'ipv6'
        option 'target' 'ACCEPT'

config 'include'
        option 'path' '/etc/firewall.user'

config 'rule'
        option '_name' 'ssh'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'tcp'
        option 'dest_port' '22'

config 'rule'
        option '_name' 'www_luci'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'tcp'
        option 'dest_port' '80'

config 'rule'
        option '_name' 'openvpn'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'udp'
        option 'dest_port' '1194'

config 'rule'
        option '_name' 'ftp'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'udp'
        option 'dest_port' '21'

config 'rule'
        option '_name' 'openvpn_lan'
        option 'src' 'lan'
        option 'target' 'ACCEPT'
        option 'proto' 'udp'
        option 'dest_port' '1194'

root@Serafin:~$ cat /etc/firewall.user
# This file is interpreted as shell script.
# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.

iptables -I OUTPUT -o tap+ -j ACCEPT
iptables -I INPUT -i tap+ -j ACCEPT
iptables -I FORWARD -o tap+ -j ACCEPT
iptables -I FORWARD -i tap+ -j ACCEPT
iptables -I OUTPUT -o tun+ -j ACCEPT
iptables -I INPUT -i tun+ -j ACCEPT
iptables -I FORWARD -o tun+ -j ACCEPT
iptables -I FORWARD -i tun+ -j ACCEPT
iptables -I OUTPUT -o tun0 -j ACCEPT
iptables -I INPUT -i tun0 -j ACCEPT
iptables -I FORWARD -o tun0 -j ACCEPT
iptables -I FORWARD -i tun0 -j ACCEPT


root@Serafin:~$ cat /etc/init.d/routing
#!/bin/sh /etc/rc.common
# routing potrzebny do komunikacji pomiedzy hostami w VPN

START=99

start() {
        sleep 100
        route add -net 192.168.2.0 netmask 255.255.255.0 gw 10.0.1.2
}


WRT160NL, hostname Stroza:

root@Stroza:~$ ifconfig
br-lan         inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
eth1          inet addr:192.168.138.2  Bcast:192.168.138.255  Mask:255.255.255.0
tun0          inet addr:10.0.1.6  P-t-P:10.0.1.5  Mask:255.255.255.255

root@Stroza:~$ cat /etc/openvpn/openvpn.conf
client
dev tun
proto udp

remote 91.X.Y.Z 1194

persist-key
persist-tun

ca /etc/openvpn/cacert.pem
cert /etc/openvpn/strozacert.pem
key /etc/openvpn/strozakey.pem_wp

#logowanie
log-append /tmp/log/openvpn.log
status /tmp/log/openvpn.status

verb 3

root@Stroza:~$ cat /etc/config/firewall
config 'defaults'
        option 'syn_flood' '1'
        option 'input' 'ACCEPT'
        option 'output' 'ACCEPT'
        option 'forward' 'REJECT'
        option 'drop_invalid' '1'

config 'zone'
        option 'name' 'lan'
        option 'network' 'lan'
        option 'input' 'ACCEPT'
        option 'output' 'ACCEPT'
        option 'forward' 'REJECT'

config 'zone'
        option 'name' 'wan'
        option 'network' 'wan'
        option 'input' 'REJECT'
        option 'output' 'ACCEPT'
        option 'forward' 'REJECT'
        option 'masq' '1'
        option 'mtu_fix' '1'

config 'forwarding'
        option 'src' 'lan'
        option 'dest' 'wan'

config 'rule'
        option 'name' 'Allow-DHCP-Renew'
        option 'src' 'wan'
        option 'proto' 'udp'
        option 'dest_port' '68'
        option 'target' 'ACCEPT'
        option 'family' 'ipv4'

config 'rule'
        option 'name' 'Allow-Ping'
        option 'src' 'wan'
        option 'proto' 'icmp'
        option 'icmp_type' 'echo-request'
        option 'family' 'ipv4'
        option 'target' 'ACCEPT'

config 'rule'
        option 'name' 'Allow-DHCPv6'
        option 'src' 'wan'
        option 'proto' 'udp'
        option 'src_ip' 'fe80::/10'
        option 'src_port' '547'
        option 'dest_ip' 'fe80::/10'
        option 'dest_port' '546'
        option 'family' 'ipv6'
        option 'target' 'ACCEPT'

config 'rule'
        option 'name' 'Allow-ICMPv6-Input'
        option 'src' 'wan'
        option 'proto' 'icmp'
        list 'icmp_type' 'echo-request'
        list 'icmp_type' 'destination-unreachable'
        list 'icmp_type' 'packet-too-big'
        list 'icmp_type' 'time-exceeded'
        list 'icmp_type' 'bad-header'
        list 'icmp_type' 'unknown-header-type'
        list 'icmp_type' 'router-solicitation'
        list 'icmp_type' 'neighbour-solicitation'
        option 'limit' '1000/sec'
        option 'family' 'ipv6'
        option 'target' 'ACCEPT'

config 'rule'
        option 'name' 'Allow-ICMPv6-Forward'
        option 'src' 'wan'
        option 'dest' '*'
        option 'proto' 'icmp'
        list 'icmp_type' 'echo-request'
        list 'icmp_type' 'destination-unreachable'
        list 'icmp_type' 'packet-too-big'
        list 'icmp_type' 'time-exceeded'
        list 'icmp_type' 'bad-header'
        list 'icmp_type' 'unknown-header-type'
        option 'limit' '1000/sec'
        option 'family' 'ipv6'
        option 'target' 'ACCEPT'

config 'include'
        option 'path' '/etc/firewall.user'

config 'rule'
        option '_name' 'ssh'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'tcp'
        option 'dest_port' '22'

config 'rule'
        option '_name' 'www_luci'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'tcp'
        option 'dest_port' '80'

config 'rule'
        option '_name' 'openvpn'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'udp'
        option 'dest_port' '1194'

config 'rule'
        option '_name' 'ftp'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'udp'
        option 'dest_port' '21'

config 'rule'
        option '_name' 'openvpn_lan'
        option 'src' 'lan'
        option 'target' 'ACCEPT'
        option 'proto' 'udp'
        option 'dest_port' '1194'

root@Stroza:~$ cat /etc/firewall.user
# This file is interpreted as shell script.
# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.


iptables -I OUTPUT -o tap+ -j ACCEPT
iptables -I INPUT -i tap+ -j ACCEPT
iptables -I FORWARD -o tap+ -j ACCEPT
iptables -I FORWARD -i tap+ -j ACCEPT
iptables -I OUTPUT -o tun+ -j ACCEPT
iptables -I INPUT -i tun+ -j ACCEPT
iptables -I FORWARD -o tun+ -j ACCEPT
iptables -I FORWARD -i tun+ -j ACCEPT
iptables -I OUTPUT -o tun0 -j ACCEPT
iptables -I INPUT -i tun0 -j ACCEPT
iptables -I FORWARD -o tun0 -j ACCEPT
iptables -I FORWARD -i tun0 -j ACCEPT

root@Stroza:~$ cat /etc/init.d/routing
#!/bin/sh /etc/rc.common
# routing potrzebny do komunikacji pomiedzy hostami w VPN

START=99

start() {
        sleep 150
        route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.1.5
}


Efekt jest taki jak na schemacie:

PunBB bbcode test

Potrzebuje uzyskać połączenie z każdego hosta w sieci 192.168.1.0 do 192.168.2.0 i odwrotnie
Wydaje Mi się że coś jest nie tak z routingiem, niestety nie mogę dojść dlaczego nie działa. Próbowałem kłaść firewalla na obydwóch urządzeniach, niestety efekt taki sam.
W razie niejasności ze schematem proszę o pytania.

Bardzo proszę o "świeże spojrzenie na problem".

2

Odp: OpenVPN połączenie między dwoma sieciami

Ja mam takie reguły na każdym z router'ow, z tym że sieci lokalne się nie widzą, klienci widzą tylko router po vpn bez uruchomionego klienta vpn, a na routerach mam zrobione przekierowania portów do odpowiednich lan'ow

iptables -I FORWARD -i br-lan -o tun0 -j ACCEPT
iptables -I FORWARD -i tun0 -o br-lan -j ACCEPT
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

3 (edytowany przez rpc 2012-03-26 09:56:38)

Odp: OpenVPN połączenie między dwoma sieciami

Może po kolei
Czyli jak rozumiem pingujesz się wzajemnie ?

znaczy się z WRT160NL (Serafin) działa ?

root@Serafin:~$ ping 10.0.1.6

oraz z WRT160NL (Stroza) działa ?

root@Stroza:~$ ping 10.0.1.1

pokaż odpowiedzi ping

Pokaż mi jeszcze zawartość pliku

/etc/config/network

4 (edytowany przez abanczak 2012-03-26 10:12:12)

Odp: OpenVPN połączenie między dwoma sieciami

Z routera Serafin:


root@Serafin:~$ ping 10.0.1.6
PING 10.0.1.6 (10.0.1.6): 56 data bytes
64 bytes from 10.0.1.6: seq=0 ttl=64 time=9.562 ms
64 bytes from 10.0.1.6: seq=1 ttl=64 time=15.048 ms
^C
--- 10.0.1.6 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 9.562/12.305/15.048 ms

root@Serafin:~$ ping 192.168.2.1
PING 192.168.2.1 (192.168.2.1): 56 data bytes
^C
--- 192.168.2.1 ping statistics ---
2 packets transmitted, 0 packets received, 100% packet loss

root@Serafin:~$ cat /etc/config/network 

config 'interface' 'loopback'
    option 'ifname' 'lo'
    option 'proto' 'static'
    option 'ipaddr' '127.0.0.1'
    option 'netmask' '255.0.0.0'

config 'interface' 'lan'
    option 'type' 'bridge'
    option 'proto' 'static'
    option 'ipaddr' '192.168.1.1'
    option 'netmask' '255.255.255.0'
    option 'ifname' 'eth0'

config 'interface' 'wan'
    option 'ifname' 'eth1'
    option '_orig_ifname' 'eth1'
    option '_orig_bridge' 'false'
    option 'proto' 'static'
    option 'ipaddr' '192.168.12.185'
    option 'netmask' '255.255.255.0'
    option 'gateway' '192.168.12.1'
    option 'dns' '8.8.8.8 91.222.116.2'

config 'switch'
    option 'name' 'eth0'
    option 'reset' '1'
    option 'enable_vlan' '1'

config 'switch_vlan'
    option 'device' 'eth0'
    option 'vlan' '1'
    option 'ports' '0 1 2 3 4 5'



Z routera Stroza:


root@Stroza:~$ ping 10.0.1.1
PING 10.0.1.1 (10.0.1.1): 56 data bytes
64 bytes from 10.0.1.1: seq=0 ttl=64 time=8.904 ms
64 bytes from 10.0.1.1: seq=1 ttl=64 time=9.112 ms
^C
--- 10.0.1.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 8.904/9.008/9.112 ms

root@Stroza:~$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: seq=0 ttl=64 time=9.745 ms
64 bytes from 192.168.1.1: seq=1 ttl=64 time=9.794 ms
^C
--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 9.745/9.769/9.794 ms


root@Stroza:~$ cat /etc/config/network

config 'interface' 'loopback'
    option 'ifname' 'lo'
    option 'proto' 'static'
    option 'ipaddr' '127.0.0.1'
    option 'netmask' '255.0.0.0'

config 'interface' 'lan'
    option 'ifname' 'eth0'
    option 'type' 'bridge'
    option 'proto' 'static'
    option 'ipaddr' '192.168.2.1'
    option 'netmask' '255.255.255.0'

config 'interface' 'wan'
    option 'ifname' 'eth1'
    option '_orig_ifname' 'eth1'
    option '_orig_bridge' 'false'
    option 'proto' 'static'
    option 'ipaddr' '192.168.138.2'
    option 'netmask' '255.255.255.0'
    option 'gateway' '192.168.138.1'
    option 'dns' '8.8.8.8 192.168.12.1'

config 'switch'
    option 'name' 'eth0'
    option 'reset' '1'
    option 'enable_vlan' '1'

config 'switch_vlan'
    option 'device' 'eth0'
    option 'vlan' '1'
    option 'ports' '0 1 2 3 4 5'


Serafin pinguje Stróże tylko po adresie Stróża.vpn, Stróża z kolei pinguje Serafina po adresie Serafin.lan i Serafin.vpn. Hosty z sieci Serafin.lan i Stróża.lan nie pingują się wzajemnie. Na schemacie użyłem strzałek żeby pokazać kierunek ping.

5

Odp: OpenVPN połączenie między dwoma sieciami

Trochę zamieszamy aby było po mojemu (czyli tak jak winno być w openwrt)
usuń swoje poniższe wpisy wpisy

root@Serafin:~$ cat /etc/init.d/routing
#!/bin/sh /etc/rc.common
# routing potrzebny do komunikacji pomiedzy hostami w VPN

START=99

start() {
        sleep 100
        route add -net 192.168.2.0 netmask 255.255.255.0 gw 10.0.1.2
}
root@Stroza:~$ cat /etc/init.d/routing
#!/bin/sh /etc/rc.common
# routing potrzebny do komunikacji pomiedzy hostami w VPN

START=99

start() {
        sleep 150
        route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.1.5
}

a zamiast nich dodaj do pliku /etc/config/network
WRT160NL-serwer, hostname Serafin:

config 'route'
        option 'interface' 'lan'
        option 'target' '192.168.2.0'
        option 'netmask' '255.255.255.0'
        option 'gateway' '10.0.1.6'
        option 'metric' '1'

       
oraz do pliku /etc/config/network
WRT160NL, hostname Stroza:

config 'route'
        option 'interface' 'lan'
        option 'target' '192.168.1.0'
        option 'netmask' '255.255.255.0'
        option 'gateway' '10.0.1.1'
        option 'metric' '1'

       
potem restart routerów

Tymi wpisami zamieniliśmy twoje ręczne na te które normalnie działają w openwrt
Krótko mówiąc zrobiliśmy porządek no i poprawiłem gateway po obu stronach

poproszę teraz po restarcie logi z obu routerów

route -n

zobaczymy jak się trasy poustawiały i czy poprawnie

6

Odp: OpenVPN połączenie między dwoma sieciami

Zamieniłeś gateway specjalnie czy literówka? Serafin nie powinien mieć gw 10.0.1.1 a Stróża 10.0.1.6?


root@Serafin:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.2        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.0.1.0        10.0.1.2        255.255.255.0   UG    0      0        0 tun0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.12.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.12.1    0.0.0.0         UG    0      0        0 eth1

root@Stroza:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.5        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.0.1.0        10.0.1.5        255.255.255.0   UG    0      0        0 tun0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.138.0   0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.138.1   0.0.0.0         UG    0      0        0 eth1

Czyli routing nie ustawił się. Ja dlatego użyłem skryptów z timeoutem, bo zastanawiałem się co się stanie gdy router wyda komendę route add a połączenie vpn jeszcze nie zdąży się ustawić?


Po ręcznym dodaniu routingów:
Serafin:

root@Serafin:~$ route add -net 192.168.2.0 netmask 255.255.255.0 gw 10.0.1.6
route: SIOCADDRT: No such process

root@Serafin:~$ route add -net 192.168.2.0 netmask 255.255.255.0 gw 10.0.1.1

root@Serafin:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.2        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
192.168.2.0     10.0.1.1        255.255.255.0   UG    0      0        0 tun0
10.0.1.0        10.0.1.2        255.255.255.0   UG    0      0        0 tun0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.12.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.12.1    0.0.0.0         UG    0      0        0 eth1

Stróża:     

root@Stroza:~$ route add -net 192.168.2.0 netmask 255.255.255.0 gw 10.0.1.1
route: SIOCADDRT: No such process

root@Stroza:~$ route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.1.6

root@Stroza:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.5        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.0.1.0        10.0.1.5        255.255.255.0   UG    0      0        0 tun0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.1.0     10.0.1.6        255.255.255.0   UG    0      0        0 tun0
192.168.138.0   0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.138.1   0.0.0.0         UG    0      0        0 eth1

dalej nie działa

7

Odp: OpenVPN połączenie między dwoma sieciami

zrób tak ja pisałem wywal routing i wpisz na dwóch routerach
iptables -I FORWARD -i br-lan -o tun0 -j ACCEPT
iptables -I FORWARD -i tun0 -o br-lan -j ACCEPT
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

8

Odp: OpenVPN połączenie między dwoma sieciami

tomi513 napisał/a:

zrób tak ja pisałem wywal routing i wpisz na dwóch routerach
iptables -I FORWARD -i br-lan -o tun0 -j ACCEPT
iptables -I FORWARD -i tun0 -o br-lan -j ACCEPT
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

Zrobiłem jak poradziłeś, niestety nic to nie dało.

9

Odp: OpenVPN połączenie między dwoma sieciami

no tak bo openvpn jeszcze się nie podniósł

No to inaczej zmień konfig na Serafinie od openvpn i dopisz trasę do sieci po stronie Serafina (patrz push)

root@Serafin:~$ cat /etc/openvpn/openvpn.conf
dev tun
port 1194
proto udp
keepalive 10 120

persist-key
persist-tun

mode server

server 10.0.1.0 255.255.255.0
ifconfig-pool-persist /tmp/ipp.txt

verb 3

tls-server
push "route 10.0.1.0 255.255.255.0"
push "route 192.168.1.0 255.255.255.0"

client-to-client

#logowanie
log-append /tmp/log/openvpn.log
status /tmp/log/openvpn.status

#certyfikaty
dh /etc/ssl/dh1024.pem
ca /etc/ssl/cacert.pem
cert /etc/ssl/servercert.pem
key /etc/ssl/private/serverkey.pem_wp

acha wykasuj te moje wpisy route z /etc/config/network
po restarcie Stroza dostanie poprawną trasę do LAN po stronie Serafina
pokaż route -n

jeden problem z głowy smile

zostanie jeszcze trasa od strony Serafina do Stroza ale to po kolei

10

Odp: OpenVPN połączenie między dwoma sieciami

Poprawiłem.

root@Stroza:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.5        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.0.1.0        10.0.1.5        255.255.255.0   UG    0      0        0 tun0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.1.0     10.0.1.5        255.255.255.0   UG    0      0        0 tun0
192.168.138.0   0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.138.1   0.0.0.0         UG    0      0        0 eth1

Pingi latają z Stróża do Serafin.tun, Serafin.lan i hosty w sieci Serafin.lan. Jesteśmy więc w punkcie wyjścia tyle że troszkę posprzątaliśmy.

11

Odp: OpenVPN połączenie między dwoma sieciami

wywal dwie linijki
push "route 10.0.1.0 255.255.255.0"
push "route 192.168.1.0 255.255.255.0"
openvpn wstaje?
pokaż logread

12

Odp: OpenVPN połączenie między dwoma sieciami

pokaż jeszcze trasę z Serafina

potem dodaj ręcznie na Serafinie po utworzeniu tunelu

route add -net 192.168.2.0 netmask 255.255.255.0 gw 10.0.1.6

i daj jeszcze raz route -n

zobacz czy po dodaniu trasy ręcznie zabangla

jeśli tak to możemy wykorzystać po stronie serwera skrypty up i down


jeśli nie to będziemy szukać przyczyny
musi działać

13

Odp: OpenVPN połączenie między dwoma sieciami

Nie bardzo rozumiem

rpc napisał/a:

pokaż jeszcze trasę z Serafina

Moje skrypty właśnie dodawały routing ręcznie, jednak:

root@Serafin:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.2        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
192.168.2.0     10.0.1.2        255.255.255.0   UG    0      0        0 tun0
10.0.1.0        10.0.1.2        255.255.255.0   UG    0      0        0 tun0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.12.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.12.1    0.0.0.0         UG    0      0        0 eth1

I nie działa. Nie jestem w stanie puścić pinga z Serafin na Stróża.lan

14

Odp: OpenVPN połączenie między dwoma sieciami

powiedz mi jeszcze jedno czy musisz mieć openvpn w trybie serwera  ?
będziesz się do niego łączył czymś innym jak drugim openwrt ?

15

Odp: OpenVPN połączenie między dwoma sieciami

W zasadzie Serafin ma adres zewnętrzny więc się do niego zawsze dostane, w przyszłości będę musiał dołożyć trzeciego OpenWRT.

Nasuwa mi się pytanie. W zasadzie szukamy problemu w routingu, ale on (chyba) od samego początku był ustawiony dobrze (moje skrypty w init.d). Zastanawia mnie fakt że w takiej konfiguracji jaka jest teraz, skoro Stróża pinguje całą sieć 192.168.1.0 to dlaczego hosty w Stroza.lan tego nie robią? To chyba jest tak, że jak router posiada odpowiednie trasy a host pcha pakiety na default gw to już router powinien wiedzieć jak to rozesłać.
Dodatkowo jak na Stróży robię nasłuch tcpdump`em na Stroza.tun a z Serafin pcham ping to tcpdump nic mi nie pokazuje. Być może problem jest w konfiguracji openvpn? Niby używam przełącznika "client-to-client", ale niestety z openvpn mam małe doświadczenie i mogłem tam się pomylić.

16

Odp: OpenVPN połączenie między dwoma sieciami

tomi513 napisał/a:

wywal dwie linijki
push "route 10.0.1.0 255.255.255.0"
push "route 192.168.1.0 255.255.255.0"
openvpn wstaje?
pokaż logread

W logread nie pokazuje nic na temat openvpn, natomiast openvpn wstaje i nawiązują się połączenia między Serafin a Stróża, jednak bez routingu nie ma pingu z Stróża na Serafin.lan

Wycofałem zmiany.

17

Odp: OpenVPN połączenie między dwoma sieciami

Zmieniłem w openvpn verb na 10 i w logach było coś takiego:


Mon Mar 26 17:37:25 2012 us=806422 stroza.localhost/91.X.Y.Z:1194 UDPv4 write returned 77
Mon Mar 26 17:37:27 2012 us=855732  event_wait returned 0
Mon Mar 26 17:37:28 2012 us=464339  event_wait returned 1
Mon Mar 26 17:37:28 2012 us=464635 UDPv4 read returned 85
Mon Mar 26 17:37:28 2012 us=465515 stroza.localhost/91.X.Y.Z:1194 UDPv4 READ [85] from 91.X.Y.Z:1194: P_DATA_V1 kid=0 DATA 8c592396 a5762364 cbfb211f 68852e0a c8246d8d 5517df35 f803afa2 e058d35[more...]
Mon Mar 26 17:37:28 2012 us=465810 stroza.localhost/91.X.Y.Z:1194 MULTI: bad source address from client [192.168.2.243], packet dropped

192.168.2.243 to jest drukarka w sieci Stroza.lan

18 (edytowany przez rpc 2012-03-26 19:00:12)

Odp: OpenVPN połączenie między dwoma sieciami

dobra właśnie to u siebie odpaliłem może nie na openwrt ale przecież powinno działać

potrzebuje wiedzieć dokładnie co pisze w polu CN certyfikatu dla clienta (za Subject:)
/etc/openvpn/strozacert.pem
a najlepiej wklej cały wiersz za "Subject:"

jak będę to miał to wyrzucę gotowe konfigi


Acha firewalla nie ruszamy na razie to się zrobi po routiungu


Ps. bez obrazy ale tomi513 nie wie co pisze a w zasadzie to nie rozumie routingu nat i w ogóle jak to działa i z czym się to je
Kolego @tomi513 trochę się należy podszkolić w sieciach a dopiero radzić co i jak a nie strzelać na ślepo.

19

Odp: OpenVPN połączenie między dwoma sieciami

Wysłałem przez PW

20 (edytowany przez rpc 2012-03-26 20:13:45)

Odp: OpenVPN połączenie między dwoma sieciami

czytaj PW
czekam na odpowiedź

21 (edytowany przez rpc 2012-03-27 10:44:29)

Odp: OpenVPN połączenie między dwoma sieciami

a więc tak

certyfikat clienta openvpn (router Stroze ) ma w polu CommonName wpis jak niżej:

CN=stroza.localhost

A więc na routerze Serafin (server openvpn) proszę utworzyć katalog ccd

mkdir /etc/openvpn/ccd

następnie w katalogu ccd tworzymy plik dokładnie o nazwie zdefiniowanej w certyfikacie clienta CN

touch /etc/openvpn/ccd/stroza.localhost

plik /etc/openvpn/ccd/stroza.localhost uzupełniamy następującą treścią:

ifconfig-push 10.0.1.5 10.0.1.6
iroute 192.168.2.0 255.255.255.0

Proszę zmodyfikować plik konfiguracyjny serwera openvpn Serafin

root@Serafin:~$ cat /etc/openvpn/openvpn.conf
dev tun
port 1194
proto udp
keepalive 10 120

persist-key
persist-tun

mode server

server 10.0.1.0 255.255.255.0
ifconfig-pool-persist /tmp/ipp.txt

verb 3

tls-server
route 192.168.2.0 255.255.255.0
push "route 10.0.1.0 255.255.255.0"
push "route 192.168.1.0 255.255.255.0"
push "route 192.168.2.0 255.255.255.0"

client-to-client
client-config-dir ccd
ccd-exclusive

#logowanie
log-append /tmp/log/openvpn.log
status /tmp/log/openvpn.status

#certyfikaty
dh /etc/ssl/dh1024.pem
ca /etc/ssl/cacert.pem
cert /etc/ssl/servercert.pem
key /etc/ssl/private/serverkey.pem_wp

Konfigurację pliku openvpn na routerze Stroza zostawiamy bez zmian czyli

root@Stroza:~$ cat /etc/openvpn/openvpn.conf
client
dev tun
proto udp

remote 91.X.Y.Z 1194

persist-key
persist-tun

ca /etc/openvpn/cacert.pem
cert /etc/openvpn/strozacert.pem
key /etc/openvpn/strozakey.pem_wp

#logowanie
log-append /tmp/log/openvpn.log
status /tmp/log/openvpn.status

verb 3

po tych operacjach serwer openvpn wyśle odpowiednie trasy do clienta oraz u siebie odpowiednio ustawi
druga rzecz to to że klient openvpn będzie miał zawsze te same adresy
po trzecie jak chcemy dodać nową sieć np. nowy router to tworzymy nowy plik w katalogu ccd z nazwą z CommonName certyfikatu clienta (musi być nowy certyfikat dodatkowy) oraz z wpisami nowych adresów ip oraz trasy

np.
Mamy dodatkowy router nazwijmy to GURU o adresie jego sieci LAN 192.168.100.0/24. Nazwa w certyfikacie CommonName to
CN=guru
plik /etc/openvpn/ccd/guru winien zawierać

ifconfig-push 10.0.1.9 10.0.1.10
iroute 192.168.100.0 255.255.255.0

oraz do pliku openvpn.conf serwera Serafin dopisujemy dwa wiersze

route 192.168.100.0 255.255.255.0
push "route 192.168.100.0 255.255.255.0"

i to wszystko

wszystkie 3 podsieci (Serafin,Stroze,GURU) będą się widzieć nawzajem. Jak dołoży się jeszcze do tego zwykłego klienta openvpn np. z pod windows bez podsieci to też będzie miał routing do pozostałych podsieci

Jeszcze jedna sprawa firewall
na razie opisałem routing
pewnie będzie potrzeba na na routerach ustawienie czegoś podobnego

iptables -I FORWARD -i tun0 -o br-lan -j ACCEPT
iptables -I FORWARD -i br-lan -o tun0 -j ACCEPT

oraz dodatkowo na Serafinie (to dla przykładu 3 routerów)

iptables -I FORWARD --src 192.168.2.0/24 --dst 192.168.100.0/24 -j ACCEPT
iptables -I FORWARD --src 192.168.100.0/24 --dst 192.168.2.0/24 -j ACCEPT

ale to w praniu wyjdzie

po ustawieniu wszystkiego pokaż na obu routerach
route -n

22

Odp: OpenVPN połączenie między dwoma sieciami

Dopiero teraz byłem w stanie konkretnie sprawdzić działanie sieci po zmianach.

zamiast

client-config-dir ccd

musiałem użyć:

client-config-dir /etc/openvpn/ccd

inaczej nie mógł znaleźć konfiguracji.

Poza tym wszystko zaczęło działać. Hosty z sieci Serafin.lan i Stróża.lan pingują się wzajemnie, pingi również lataj na każdy interfejs routerów.


Pozostało powiedzieć dzięki!

23

Odp: OpenVPN połączenie między dwoma sieciami

może to właściwość openvpn w openwrt

a co z firewallem
musiałeś jakieś zmiany wprowadzić czy zaczęło chodzić od razu ?

pytam bo chcę to wszystko zebrać do kupy.

czyli interesują mnie zmiany firewalla czy były jakieś czy nie
oraz jakby można prosiłbym o
route -n z obu routerów
chce zobaczyć jak trasy się ustawiły

poza tym jeśli nie było by problemem to
iptables -t nat -L -v
iptables -L -v
z obu routerów

może być na PW

24

Odp: OpenVPN połączenie między dwoma sieciami

Jeżeli chodzi o firewalla to wydałem tylko komendy, które podałeś w poście #21, reszta jest praktycznie defaultowa, nie licząc portów dla ssh, luci itp. poniżej wklejam wyniki o które prosiłeś. Trzeba jednak pamiętać, że jak sam próbowałem rozwiązać problem to mogłem grubo namieszać w firewallu i część rzeczy może być niepotrzebna. W najbliższym czasie będę z tym robił porządki wtedy mogę wstawić nową, "czystą konfigurację".


Stróża:

root@Stroza:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.6        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.0.1.0        10.0.1.6        255.255.255.0   UG    0      0        0 tun0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.1.0     10.0.1.6        255.255.255.0   UG    0      0        0 tun0
192.168.138.0   0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.138.1   0.0.0.0         UG    0      0        0 eth1
root@Stroza:~$ iptables -t nat -L -v
Chain PREROUTING (policy ACCEPT 71 packets, 6371 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   71  6371 prerouting_rule  all  --  any    any     anywhere             anywhere            
    0     0 zone_lan_prerouting  all  --  br-lan any     anywhere             anywhere            
   68  6183 zone_wan_prerouting  all  --  eth1   any     anywhere             anywhere            

Chain POSTROUTING (policy ACCEPT 25 packets, 3008 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  205 16042 postrouting_rule  all  --  any    any     anywhere             anywhere            
    9  2048 zone_lan_nat  all  --  any    br-lan  anywhere             anywhere            
  180 13034 zone_wan_nat  all  --  any    eth1    anywhere             anywhere            

Chain OUTPUT (policy ACCEPT 190 packets, 15442 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain nat_reflection_in (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain nat_reflection_out (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain postrouting_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  205 16042 nat_reflection_out  all  --  any    any     anywhere             anywhere            

Chain prerouting_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain prerouting_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   71  6371 nat_reflection_in  all  --  any    any     anywhere             anywhere            

Chain prerouting_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain zone_lan_nat (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain zone_lan_prerouting (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 prerouting_lan  all  --  any    any     anywhere             anywhere            

Chain zone_wan_nat (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  180 13034 MASQUERADE  all  --  any    any     anywhere             anywhere            

Chain zone_wan_prerouting (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   68  6183 prerouting_wan  all  --  any    any     anywhere             anywhere    
root@Stroza:~$ iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   68  5770 ACCEPT     all  --  tun+   any     anywhere             anywhere            
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID 
  619 56042 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
   16   960 ACCEPT     all  --  lo     any     anywhere             anywhere            
   17   828 syn_flood  tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN 
  121 14586 input_rule  all  --  any    any     anywhere             anywhere            
  121 14586 input      all  --  any    any     anywhere             anywhere            

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  tun+   any     anywhere             anywhere            
    0     0 ACCEPT     all  --  any    tun+    anywhere             anywhere            
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID 
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
    0     0 forwarding_rule  all  --  any    any     anywhere             anywhere            
    0     0 forward    all  --  any    any     anywhere             anywhere            
    0     0 reject     all  --  any    any     anywhere             anywhere            
    0     0 ACCEPT     all  --  tun+   any     anywhere             anywhere            

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   53 11530 ACCEPT     all  --  any    tun+    anywhere             anywhere            
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID 
  454 47408 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
   16   960 ACCEPT     all  --  any    lo      anywhere             anywhere            
  224 21162 output_rule  all  --  any    any     anywhere             anywhere            
  224 21162 output     all  --  any    any     anywhere             anywhere            

Chain forward (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 zone_lan_forward  all  --  br-lan any     anywhere             anywhere            
    0     0 zone_wan_forward  all  --  eth1   any     anywhere             anywhere            

Chain forwarding_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain forwarding_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 nat_reflection_fwd  all  --  any    any     anywhere             anywhere            

Chain forwarding_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain input (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   52  8298 zone_lan   all  --  br-lan any     anywhere             anywhere            
   69  6288 zone_wan   all  --  eth1   any     anywhere             anywhere            

Chain input_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain input_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain input_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain nat_reflection_fwd (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain output (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  224 21162 zone_lan_ACCEPT  all  --  any    any     anywhere             anywhere            
  172 12864 zone_wan_ACCEPT  all  --  any    any     anywhere             anywhere            

Chain output_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain reject (5 references)
 pkts bytes target     prot opt in     out     source               destination         
   15   732 REJECT     tcp  --  any    any     anywhere             anywhere            reject-with tcp-reset 
   52  5460 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-port-unreachable 

Chain syn_flood (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   17   828 RETURN     tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN limit: avg 25/sec burst 50 
    0     0 DROP       all  --  any    any     anywhere             anywhere            

Chain zone_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:openvpn 
   52  8298 input_lan  all  --  any    any     anywhere             anywhere            
   52  8298 zone_lan_ACCEPT  all  --  any    any     anywhere             anywhere            

Chain zone_lan_ACCEPT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
   52  8298 ACCEPT     all  --  any    br-lan  anywhere             anywhere            
   52  8298 ACCEPT     all  --  br-lan any     anywhere             anywhere            

Chain zone_lan_DROP (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  any    br-lan  anywhere             anywhere            
    0     0 DROP       all  --  br-lan any     anywhere             anywhere            

Chain zone_lan_REJECT (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 reject     all  --  any    br-lan  anywhere             anywhere            
    0     0 reject     all  --  br-lan any     anywhere             anywhere            

Chain zone_lan_forward (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 zone_wan_ACCEPT  all  --  any    any     anywhere             anywhere            
    0     0 forwarding_lan  all  --  any    any     anywhere             anywhere            
    0     0 zone_lan_REJECT  all  --  any    any     anywhere             anywhere            

Chain zone_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:bootpc 
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere            icmp echo-request 
    2    96 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:ssh 
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:www 
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:openvpn 
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:21 
   67  6192 input_wan  all  --  any    any     anywhere             anywhere            
   67  6192 zone_wan_REJECT  all  --  any    any     anywhere             anywhere            

Chain zone_wan_ACCEPT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
  172 12864 ACCEPT     all  --  any    eth1    anywhere             anywhere            
    0     0 ACCEPT     all  --  eth1   any     anywhere             anywhere            

Chain zone_wan_DROP (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  any    eth1    anywhere             anywhere            
    0     0 DROP       all  --  eth1   any     anywhere             anywhere            

Chain zone_wan_REJECT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 reject     all  --  any    eth1    anywhere             anywhere            
   67  6192 reject     all  --  eth1   any     anywhere             anywhere            

Chain zone_wan_forward (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 forwarding_wan  all  --  any    any     anywhere             anywhere            
    0     0 zone_wan_REJECT  all  --  any    any     anywhere             anywhere        

Serafin:

root@Serafin:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.2        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.0.1.0        10.0.1.2        255.255.255.0   UG    0      0        0 tun0
192.168.2.0     10.0.1.2        255.255.255.0   UG    0      0        0 tun0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
192.168.12.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1
0.0.0.0         192.168.12.1    0.0.0.0         UG    0      0        0 eth1
root@Serafin:~$ iptables -t nat -L -v
Chain PREROUTING (policy ACCEPT 1662 packets, 178K bytes)
 pkts bytes target     prot opt in     out     source               destination         
 1662  178K prerouting_rule  all  --  any    any     anywhere             anywhere            
   78 10530 zone_lan_prerouting  all  --  br-lan any     anywhere             anywhere            
 1584  168K zone_wan_prerouting  all  --  eth1   any     anywhere             anywhere            

Chain POSTROUTING (policy ACCEPT 30 packets, 3777 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  193 15733 postrouting_rule  all  --  any    any     anywhere             anywhere            
   11  2629 zone_lan_nat  all  --  any    br-lan  anywhere             anywhere            
  163 11956 zone_wan_nat  all  --  any    eth1    anywhere             anywhere            

Chain OUTPUT (policy ACCEPT 183 packets, 15333 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain nat_reflection_in (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain nat_reflection_out (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain postrouting_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  193 15733 nat_reflection_out  all  --  any    any     anywhere             anywhere            

Chain prerouting_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain prerouting_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         
 1662  178K nat_reflection_in  all  --  any    any     anywhere             anywhere            

Chain prerouting_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain zone_lan_nat (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain zone_lan_prerouting (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   78 10530 prerouting_lan  all  --  any    any     anywhere             anywhere            

Chain zone_wan_nat (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  163 11956 MASQUERADE  all  --  any    any     anywhere             anywhere            

Chain zone_wan_prerouting (1 references)
 pkts bytes target     prot opt in     out     source               destination         
 1584  168K prerouting_wan  all  --  any    any     anywhere             anywhere    
root@Serafin:~$ iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  399 54842 ACCEPT     all  --  tun+   any     anywhere             anywhere            
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID 
 1990  217K ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
   16   960 ACCEPT     all  --  lo     any     anywhere             anywhere            
   14   708 syn_flood  tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN 
 1696  490K input_rule  all  --  any    any     anywhere             anywhere            
 1696  490K input      all  --  any    any     anywhere             anywhere            

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  tun+   any     anywhere             anywhere            
    0     0 ACCEPT     all  --  any    tun+    anywhere             anywhere            
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID 
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
    7  1665 forwarding_rule  all  --  any    any     anywhere             anywhere            
    7  1665 forward    all  --  any    any     anywhere             anywhere            
    1   336 reject     all  --  any    any     anywhere             anywhere            
    0     0 ACCEPT     all  --  tun+   any     anywhere             anywhere            

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  505 40266 ACCEPT     all  --  any    tun+    anywhere             anywhere            
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID 
 2032  221K ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
   16   960 ACCEPT     all  --  any    lo      anywhere             anywhere            
  210 21083 output_rule  all  --  any    any     anywhere             anywhere            
  210 21083 output     all  --  any    any     anywhere             anywhere            

Chain forward (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    6  1329 zone_lan_forward  all  --  br-lan any     anywhere             anywhere            
    0     0 zone_wan_forward  all  --  eth1   any     anywhere             anywhere            

Chain forwarding_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain forwarding_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    5  1155 nat_reflection_fwd  all  --  any    any     anywhere             anywhere            

Chain forwarding_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain input (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   56  9475 zone_lan   all  --  br-lan any     anywhere             anywhere            
 1639  480K zone_wan   all  --  eth1   any     anywhere             anywhere            

Chain input_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain input_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain input_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain nat_reflection_fwd (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain output (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  210 21083 zone_lan_ACCEPT  all  --  any    any     anywhere             anywhere            
  154 11624 zone_wan_ACCEPT  all  --  any    any     anywhere             anywhere            

Chain output_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain reject (5 references)
 pkts bytes target     prot opt in     out     source               destination         
   10   492 REJECT     tcp  --  any    any     anywhere             anywhere            reject-with tcp-reset 
 1620  478K REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-port-unreachable 

Chain syn_flood (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   14   708 RETURN     tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN limit: avg 25/sec burst 50 
    0     0 DROP       all  --  any    any     anywhere             anywhere            

Chain zone_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:openvpn 
   56  9475 input_lan  all  --  any    any     anywhere             anywhere            
   56  9475 zone_lan_ACCEPT  all  --  any    any     anywhere             anywhere            

Chain zone_lan_ACCEPT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
   56  9459 ACCEPT     all  --  any    br-lan  anywhere             anywhere            
   56  9475 ACCEPT     all  --  br-lan any     anywhere             anywhere            

Chain zone_lan_DROP (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  any    br-lan  anywhere             anywhere            
    0     0 DROP       all  --  br-lan any     anywhere             anywhere            

Chain zone_lan_REJECT (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    6  1329 reject     all  --  any    br-lan  anywhere             anywhere            
    0     0 reject     all  --  br-lan any     anywhere             anywhere            

Chain zone_lan_forward (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    6  1329 zone_wan_ACCEPT  all  --  any    any     anywhere             anywhere            
    6  1329 forwarding_lan  all  --  any    any     anywhere             anywhere            
    6  1329 zone_lan_REJECT  all  --  any    any     anywhere             anywhere            

Chain zone_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    8  2624 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:bootpc 
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere            icmp echo-request 
    4   216 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:ssh 
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:www 
    4   168 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:openvpn 
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:21 
 1623  477K input_wan  all  --  any    any     anywhere             anywhere            
 1623  477K zone_wan_REJECT  all  --  any    any     anywhere             anywhere            

Chain zone_wan_ACCEPT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
  154 11624 ACCEPT     all  --  any    eth1    anywhere             anywhere            
    0     0 ACCEPT     all  --  eth1   any     anywhere             anywhere            

Chain zone_wan_DROP (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  any    eth1    anywhere             anywhere            
    0     0 DROP       all  --  eth1   any     anywhere             anywhere            

Chain zone_wan_REJECT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 reject     all  --  any    eth1    anywhere             anywhere            
 1623  477K reject     all  --  eth1   any     anywhere             anywhere            

Chain zone_wan_forward (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 forwarding_wan  all  --  any    any     anywhere             anywhere            
    0     0 zone_wan_REJECT  all  --  any    any     anywhere             anywhere  

25 (edytowany przez rpc 2012-03-29 20:49:59)

Odp: OpenVPN połączenie między dwoma sieciami

no fakt namieszane smile

ale nie widzę moich reguł iptables za to widzę inne

    0     0 ACCEPT     all  --  tun+   any     anywhere             anywhere            
    0     0 ACCEPT     all  --  any    tun+    anywhere             anywhere 

o ile do pierwszego się nie przykleję o tyle drugi wiersz teoretycznie dopuszcza ruch m/innymi z internetu do tun+ bez ograniczeń

dlatego ja użyłem od tun0 do br-lan i viceversa

zresztą zamiast do FORWARD lepiej wrzucić do łańcucha forwarding_rule ponieważ łańcuch ustawi się za ESTABLISHED i RELATED
więc przejdzie przez te reguły jeśli wcześniej było nawiązane połączenie
W ogóle to generalnie wszelkie nasze zmiany lepiej wrzucać do forwarding_rule


hmm czyli nie wiem czy te reguły są wystarczające

ale i tak dziękuję

Ps. A czy kolega miały ochotę na jeszcze jeden eksperyment z openwrt i openvpn.
Zastanawia mnie co się stanie jak w network doda się następującą sekcję

config 'interface' 'tun0'
        option 'ifname' 'tun0'
        option 'proto' 'none'

zastanawia mnie czy poprawnie podniesie się tunel i zostaną przydzielone odpowiednie adresy
jeśli tak była by to furtka do podciągnięcia firewalla od openwrt po to aby nie kombinować z ręcznymi ustawieniami

Ps. teraz wiem, że będzie ok. Co prawda przetestowałem na ipv6 ale reguły się ładują

A więc tak.
Aby sobie to ładnie zrobić wedle openwrt (mówię o pliku network i firewall bez żadnych wpisów ręcznych) powinno się
dodać
do pliku /etc/config/network

config 'interface' 'openvpn_tun0'
        option 'ifname' 'tun0'
        option 'proto' 'none'

do pliku /etc/config/firewall

config zone
        option name             'openvpn_tun0'
        option network          'openvpn_tun0'
        option input            REJECT
        option output           ACCEPT
        option forward          REJECT
        option mtu_fix          1

config forwarding
        option src              lan
        option dest             'openvpn_tun0'

config forwarding
        option src              'openvpn_tun0'
        option dest             'lan'

#Allow ssh
config rule
        option src              'openvpn_tun0'
        option proto            tcp
        option dest_port        22
        option target           ACCEPT

# Allow IPv4 ping
config rule
        option src              'openvpn_tun0'
        option proto            icmp
        option icmp_type        echo-request
        option family           ipv4
        option target           ACCEPT

no i do pełni szczęści jeszcze dodajemy do dhcp nowy interfejs

config dhcp 'openvpn_tun0'
        option interface        'openvpn_tun0'
        option ignore   1

od teraz mamy oddzielne reguły dla openvpn + ochrona routera tylko ssh i ping dostępne. Jak ktoś chce więcej to dodaje sobie regułę i git