# vi /etc/rc.conf ( PF)
pf=YES
# vi /etc/sysctl.conf ( )
net.inet.ip.forwarding=1
# vi /etc/rc.local ( static_routes )
/etc/static_routes
# vi /etc/hostname.lo1
!ifconfig lo1 create
!ifconfig lo1 192.168.254.1 netmask 255.255.255.255
# vi /etc/hostname.gif0
!ifconfig gif0 create
!ifconfig gif0 192.168.255.1 netmask 255.255.255.252 192.168.255.2
!ifconfig gif0 tunnel 11.11.11.1 22.22.22.2
!ifconfig gif0 up
# vi /etc/hostname.gif1
!ifconfig gif1 create
!ifconfig gif1 192.168.255.3 netmask 255.255.255.252 192.168.255.4
!ifconfig gif1 tunnel 11.11.11.1 33.33.33.3
!ifconfig gif1 up
# chmod 640 /etc/hostname.*
# vi /etc/static_routes
/sbin/route add -host 192.168.254.2 192.168.255.2
/sbin/route add -net 192.168.15.0/24 192.168.255.2
/sbin/route add -host 192.168.254.3 192.168.255.4
/sbin/route add -net 192.168.16.0/24 192.168.255.4
# chmod a+x /etc/static_routes
# vi /etc/pf.conf
ext_if="vic0"
int_if="vic1"
set skip on lo
set skip on gif0
set skip on gif1
match in all scrub (no-df)
match out all scrub (no-df)
match on $ext_if from 192.168.0.0/16 to !192.168.0.0/16 binat-to ($ext_if:0)
block in on $int_if
pass in quick on $int_if from 192.168.0.0/16 to 192.168.0.0/16 keep state
pass out quick on $int_if from 192.168.0.0/16 to 192.168.0.0/16 keep state
# reboot
# vi /etc/hostname.lo1
!ifconfig lo1 create
!ifconfig lo1 192.168.254.2 netmask 255.255.255.255
# vi /etc/hostname.gif0
!ifconfig gif0 create
!ifconfig gif0 192.168.255.2 netmask 255.255.255.252 192.168.255.1
!ifconfig gif0 tunnel 22.22.22.2 11.11.11.1
!ifconfig gif0 up
# chmod 640 /etc/hostname.*
# vi /etc/static_routes
/sbin/route add -net 192.168.0.0/16 192.168.255.2
# chmod a+x /etc/static_routes
# vi /etc/pf.conf
ext_if="vic0"
int_if="vic1"
set skip on lo
set skip on gif0
match in all scrub (no-df)
match out all scrub (no-df)
match on $ext_if from 192.168.0.0/16 to !192.168.0.0/16 binat-to ($ext_if:0)
block in on $int_if
pass in quick on $int_if from 192.168.0.0/16 to 192.168.0.0/16 keep state
pass out quick on $int_if from 192.168.0.0/16 to 192.168.0.0/16 keep state
# reboot
# vi /etc/hostname.lo1
!ifconfig lo1 create
!ifconfig lo1 192.168.254.3 netmask 255.255.255.255
# vi /etc/hostname.gif0
!ifconfig gif0 create
!ifconfig gif0 192.168.255.4 netmask 255.255.255.252 192.168.255.3
!ifconfig gif0 tunnel 33.33.33.3 11.11.11.1
!ifconfig gif0 up
# chmod 640 /etc/hostname.*
# vi /etc/static_routes
/sbin/route add -net 192.168.0.0/16 192.168.255.4
# chmod a+x /etc/static_routes
# vi /etc/pf.conf
ext_if="vic0"
int_if="vic1"
set skip on lo
set skip on gif0
match in all scrub (no-df)
match out all scrub (no-df)
match on $ext_if from 192.168.0.0/16 to !192.168.0.0/16 binat-to ($ext_if:0)
block in on $int_if
pass in quick on $int_if from 192.168.0.0/16 to 192.168.0.0/16 keep state
pass out quick on $int_if from 192.168.0.0/16 to 192.168.0.0/16 keep state
# reboot
# traceroute 192.168.15.2
traceroute to 192.168.15.2 (192.168.15.2), 64 hops max, 40 byte packets
1 192.168.14.1 (192.168.14.1) 0.437 ms 0.215 ms 0.294 ms
2 192.168.255.2 (192.168.255.2) 0.934 ms 0.674 ms 0.646 ms
3 192.168.15.2 (192.168.15.2) 1.107 ms 1.3 ms 0.920 ms
# traceroute 192.168.16.2
traceroute to 192.168.16.2 (192.168.16.2), 64 hops max, 40 byte packets
1 192.168.14.1 (192.168.14.1) 0.356 ms 0.206 ms 0.192 ms
2 192.168.255.4 (192.168.255.4) 0.748 ms 0.666 ms 0.631 ms
3 192.168.16.2 (192.168.16.2) 0.940 ms 0.892 ms 0.843 ms
# traceroute 192.168.14.2
traceroute to 192.168.14.2 (192.168.14.2), 64 hops max, 40 byte packets
1 192.168.15.1 (192.168.15.1) 0.745 ms 0.208 ms 0.294 ms
2 192.168.255.1 (192.168.255.1) 0.768 ms 0.855 ms 0.677 ms
3 192.168.14.2 (192.168.14.2) 0.933 ms 0.830 ms 0.853 ms
# traceroute 192.168.16.2
traceroute to 192.168.16.2 (192.168.16.2), 64 hops max, 40 byte packets
1 192.168.15.1 (192.168.15.1) 0.450 ms 0.207 ms 0.372 ms
2 192.168.255.1 (192.168.255.1) 0.710 ms 1.290 ms 0.711 ms
3 192.168.255.4 (192.168.255.4) 1.243 ms 1.194 ms 1.42 ms
4 192.168.16.2 (192.168.16.2) 1.341 ms 1.445 ms 1.315 ms
# traceroute 192.168.14.2
traceroute to 192.168.14.2 (192.168.14.2), 64 hops max, 40 byte packets
1 192.168.16.1 (192.168.16.1) 0.480 ms 0.222 ms 0.191 ms
2 192.168.255.3 (192.168.255.3) 0.814 ms 0.775 ms 0.715 ms
3 192.168.14.2 (192.168.14.2) 1.168 ms 1.43 ms 0.861 ms
# traceroute 192.168.15.2
traceroute to 192.168.15.2 (192.168.15.2), 64 hops max, 40 byte packets
1 192.168.16.1 (192.168.16.1) 0.458 ms 0.234 ms 0.269 ms
2 192.168.255.3 (192.168.255.3) 0.780 ms 0.642 ms 0.661 ms
3 192.168.255.2 (192.168.255.2) 1.171 ms 0.989 ms 1.11 ms
4 192.168.15.2 (192.168.15.2) 1.519 ms 1.595 ms 1.333 ms
Source: https://habr.com/ru/post/117668/
All Articles