Firewall: Settings: Advanced
Shared forwarding - Use shared forwarding between packet filter, traffic shaper and captive portalUsing policy routing in the packet filter rules causes packets to skip processing for the traffic shaper and captive portal tasks. Using this option enables the sharing of such forwarding decisions between all components to accommodate complex setups.
+-------------------+ +------------------+ | OPNsense Site A | IPsec VTI | OPNsense Site B | |-------------------| |------------------| | LAN 192.168.1.1 | | LAN 192.168.2.1 | | OPT1 192.168.101.1| | | | WAN 172.16.0.189 |==================| WAN 172.16.0.190| | ipsec2 10.20.30.2 | | ipsec2 10.20.30.3| +-------------------+ +------------------+ || || Policy-based Tunnel || +-------------------+ | OPNsense Site C | |-------------------| | LAN 192.168.3.1 | | WAN 172.16.0.191 | +-------------------+
net.enc.in.ipsec_filter_mask IPsec input firewall filter mask runtime 0net.enc.out.ipsec_filter_mask IPsec output firewall filter mask runtime 0net.inet.ipsec.filtertunnel If set, filter packets from an IPsec tunnel. runtime 0net.inet6.ipsec6.filtertunnel If set, filter packets from an IPsec tunnel. runtime 0
route add -net 192.168.2.0/24 10.20.30.3
kldload ipfw
service ipfw onerestart
ipfw list
00100 allow pfsync from any to any00110 allow carp from any to any00120 allow layer2 mac-type 0x0806,0x803500130 allow layer2 mac-type 0x888e,0x88c700140 allow layer2 mac-type 0x8863,0x886400150 deny layer2 not mac-type 0x0800,0x86dd00200 skipto 60000 ip6 from ::1 to any00201 skipto 60000 ip4 from 127.0.0.0/8 to any00202 skipto 60000 ip6 from any to ::100203 skipto 60000 ip4 from any to 127.0.0.0/806000 skipto 60000 tcp from any to any out06199 skipto 60000 ip from any to any60000 return65533 allow ip from any to any65534 deny ip from any to any65535 allow ip from any to any
ipfw add 00005 divert 8668 ip from 192.168.101.0/24 to 192.168.2.0/24ipfw add 00006 divert 8668 ip from 192.168.101.0/24 to 192.168.3.0/24
route add -net 192.168.2.0/24 10.20.30.3route add -net 192.168.3.0/24 172.16.0.191
/etc/rc.conf
keymap="de.noacc.kbd"natd_enable="YES"natd_flags="-a 192.168.1.1 -redirect_address 192.168.101.1 192.168.1.1"
service natd restart
root@OPNsenseA:~ # ping -S 192.168.101.1 192.168.2.1PING 192.168.2.1 (192.168.2.1) from 192.168.101.1: 56 data bytes64 bytes from 192.168.2.1: icmp_seq=0 ttl=64 time=0.755 ms64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.732 ms64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.760 ms
root@OPNsenseB:~ # tcpdump -i enc0 -n host 192.168.2.1tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enc0, link-type ENC (OpenBSD encapsulated IP), capture size 262144 bytes08:48:41.013508 (authentic,confidential): SPI 0xc9014910: IP 192.168.1.1 > 192.168.2.1: ICMP echo request, id 61125, seq 0, length 6408:48:41.013609 (authentic,confidential): SPI 0xc453dc2a: IP 192.168.2.1 > 192.168.1.1: ICMP echo reply, id 61125, seq 0, length 6408:48:42.064250 (authentic,confidential): SPI 0xc9014910: IP 192.168.1.1 > 192.168.2.1: ICMP echo request, id 61125, seq 1, length 6408:48:42.064342 (authentic,confidential): SPI 0xc453dc2a: IP 192.168.2.1 > 192.168.1.1: ICMP echo reply, id 61125, seq 1, length 6408:48:43.136055 (authentic,confidential): SPI 0xc9014910: IP 192.168.1.1 > 192.168.2.1: ICMP echo request, id 61125, seq 2, length 6408:48:43.136145 (authentic,confidential): SPI 0xc453dc2a: IP 192.168.2.1 > 192.168.1.1: ICMP echo reply, id 61125, seq 2, length 64
ipfw add 00040 deny icmp from any to any
root@OPNsenseA:~ # ping 192.168.2.1PING 192.168.2.1 (192.168.2.1): 56 data bytesping: sendto: Permission deniedping: sendto: Permission denied
root@OPNsenseB:~ # ping 192.168.1.1PING 192.168.1.1 (192.168.1.1): 56 data bytes^C--- 192.168.1.1 ping statistics ---4 packets transmitted, 0 packets received, 100.0% packet loss
root@OPNsenseA:~ # ping -S 192.168.101.1 192.168.3.1PING 192.168.3.1 (192.168.3.1) from 192.168.101.1: 56 data bytes64 bytes from 192.168.3.1: icmp_seq=0 ttl=64 time=1.231 ms64 bytes from 192.168.3.1: icmp_seq=1 ttl=64 time=0.754 ms64 bytes from 192.168.3.1: icmp_seq=2 ttl=64 time=0.920 ms^C--- 192.168.3.1 ping statistics ---3 packets transmitted, 3 packets received, 0.0% packet lossround-trip min/avg/max/stddev = 0.754/0.969/1.231/0.198 ms
root@OPNsenseA:~ # tcpdump -i enc0 -n not net 10.20.30.0/24tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enc0, link-type ENC (OpenBSD encapsulated IP), capture size 262144 bytes10:55:37.713685 (authentic,confidential): SPI 0xc96a6d76: IP 192.168.1.1 > 192.168.3.1: ICMP echo request, id 53976, seq 0, length 6410:55:37.714290 (authentic,confidential): SPI 0xc843e965: IP 192.168.3.1 > 192.168.1.1: ICMP echo reply, id 53976, seq 0, length 6410:55:38.783108 (authentic,confidential): SPI 0xc96a6d76: IP 192.168.1.1 > 192.168.3.1: ICMP echo request, id 53976, seq 1, length 6410:55:38.783573 (authentic,confidential): SPI 0xc843e965: IP 192.168.3.1 > 192.168.1.1: ICMP echo reply, id 53976, seq 1, length 6410:55:39.854198 (authentic,confidential): SPI 0xc96a6d76: IP 192.168.1.1 > 192.168.3.1: ICMP echo request, id 53976, seq 2, length 6410:55:39.854896 (authentic,confidential): SPI 0xc843e965: IP 192.168.3.1 > 192.168.1.1: ICMP echo reply, id 53976, seq 2, length 64
root@OPNsense:~ # tcpdump -i enc0 -ntcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enc0, link-type ENC (OpenBSD encapsulated IP), capture size 262144 bytes10:55:37.713917 (authentic,confidential): SPI 0xc96a6d76: IP 192.168.1.1 > 192.168.3.1: ICMP echo request, id 53976, seq 0, length 6410:55:37.714029 (authentic,confidential): SPI 0xc843e965: IP 192.168.3.1 > 192.168.1.1: ICMP echo reply, id 53976, seq 0, length 6410:55:38.783298 (authentic,confidential): SPI 0xc96a6d76: IP 192.168.1.1 > 192.168.3.1: ICMP echo request, id 53976, seq 1, length 6410:55:38.783381 (authentic,confidential): SPI 0xc843e965: IP 192.168.3.1 > 192.168.1.1: ICMP echo reply, id 53976, seq 1, length 6410:55:39.854391 (authentic,confidential): SPI 0xc96a6d76: IP 192.168.1.1 > 192.168.3.1: ICMP echo request, id 53976, seq 2, length 6410:55:39.854513 (authentic,confidential): SPI 0xc843e965: IP 192.168.3.1 > 192.168.1.1: ICMP echo reply, id 53976, seq 2, length 64
root@OPNsenseA:~ # swanctl --list-sasno files found matching '/usr/local/etc/strongswan.opnsense.d/*.conf'99e0e1c1-285e-45cd-b4ef-61dcc914c879: #10, ESTABLISHED, IKEv2, 64e822915de2c77c_i* f9322b2b8d08c3f9_r local '172.16.0.189' @ 172.16.0.189[4500] remote '172.16.0.190' @ 172.16.0.190[4500] AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_256 established 4904s ago, rekeying in 8431s c24cc267-6c7e-4993-8bca-d55a1a36fc92: #6, reqid 2, INSTALLED, TUNNEL, ESP:AES_CBC-128/HMAC_SHA2_256_128 installed 1419s ago, rekeying in 1863s, expires in 2541s in cc6a1148, 32241 bytes, 445 packets out ca9c2e5c, 94340 bytes, 647 packets local 172.16.0.189/32 remote 172.16.0.190/322cb5596b-8866-4675-bfe3-6743851fa95e: #29, ESTABLISHED, IKEv2, 3c5f14c4aff43214_i 9fb73ebfee8e3639_r* local '172.16.0.189' @ 172.16.0.189[4500] remote '172.16.0.191' @ 172.16.0.191[4500] AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_256 established 716s ago, rekeying in 12374s 46f91ed0-3152-4fce-9ec5-2644e60ad11d: #7, reqid 1, INSTALLED, TUNNEL, ESP:AES_CBC-128/HMAC_SHA2_256_128 installed 716s ago, rekeying in 2561s, expires in 3244s in c843e965, 504 bytes, 6 packets, 679s ago out c96a6d76, 936 bytes, 6 packets, 679s ago local 192.168.1.0/24 remote 192.168.3.0/24root@OPNsenseB:~ # swanctl --list-sasno files found matching '/usr/local/etc/strongswan.opnsense.d/*.conf'bc96997e-6b9e-4b81-805d-48a1135d4560: #17, ESTABLISHED, IKEv2, 64e822915de2c77c_i f9322b2b8d08c3f9_r* local '172.16.0.190' @ 172.16.0.190[4500] remote '172.16.0.189' @ 172.16.0.189[4500] AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_256 established 4903s ago, rekeying in 8853s bad2434e-38cd-4d07-9908-8a73e60e1e21: #35, reqid 2, INSTALLED, TUNNEL, ESP:AES_CBC-128/HMAC_SHA2_256_128 installed 1418s ago, rekeying in 1862s, expires in 2542s in ca9c2e5c, 47253 bytes, 645 packets out cc6a1148, 64272 bytes, 444 packets local 172.16.0.190/32 remote 172.16.0.189/32root@OPNsenseC:~ # swanctl --list-sasno files found matching '/usr/local/etc/strongswan.opnsense.d/*.conf'29a73eff-323d-458d-9203-62f64dff2275: #15, ESTABLISHED, IKEv2, 3c5f14c4aff43214_i* 9fb73ebfee8e3639_r local '172.16.0.191' @ 172.16.0.191[4500] remote '172.16.0.189' @ 172.16.0.189[4500] AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_256 established 717s ago, rekeying in 12424s 2f5a11bf-9f31-444a-9986-e5f3b694624d: #5, reqid 1, INSTALLED, TUNNEL, ESP:AES_CBC-128/HMAC_SHA2_256_128 installed 717s ago, rekeying in 2566s, expires in 3243s in c96a6d76, 504 bytes, 6 packets, 680s ago out c843e965, 936 bytes, 6 packets, 680s ago local 192.168.3.0/24 remote 192.168.1.0/24
divert-to <host> port <port> Used to redirect packets to a local socket bound to host and port. The packets will not be modified, so getsockname(2) on the socket will return the original destination address of the packet.
pass in log quick on hn2 from 192.168.101.1 to {any}pass out log quick on ipsec2 from 192.168.101.1 to 192.168.2.1 divert-to localhost port 8668
root@OPNsense:~ # ls /boot/kernel/*ipfw_nat*/boot/kernel/ipfw_nat.ko /boot/kernel/ipfw_nat64.ko
kldstat | grep ipfw_nat
kldload ipfw_nat
pfw add 00050 nat 1 all from 192.168.101.0/24 to 192.168.2.0/24 via ipsec2
ipfw nat 1 config if ipsec2 ip 192.168.1.1
ipfw list00050 nat 1 ip from 192.168.101.0/24 to 192.168.2.0/24 via ipsec200100 allow pfsync from any to any00110 allow carp from any to any00120 allow layer2 mac-type 0x0806,0x803500130 allow layer2 mac-type 0x888e,0x88c700140 allow layer2 mac-type 0x8863,0x886400150 deny layer2 not mac-type 0x0800,0x86dd00200 skipto 60000 ip6 from ::1 to any00201 skipto 60000 ip4 from 127.0.0.0/8 to any00202 skipto 60000 ip6 from any to ::100203 skipto 60000 ip4 from any to 127.0.0.0/806000 skipto 60000 tcp from any to any out06199 skipto 60000 ip from any to any60000 return65533 allow ip from any to any65535 allow ip from any to any
root@OPNsense:~ # ipfw nat show configipfw nat 1 config if ipsec2