4 # This script sets up a virtual point-to-point WAN link between
5 # two subnets, using UDP packets as the ``WAN connection.''
6 # The two subnets might be non-routable addresses behind a
10 # Here define the local and remote inside networks as well
11 # as the local and remote outside IP addresses and UDP port
12 # number that will be used for the tunnel.
14 LOC_INTERIOR_IP
=192.168.1.1
15 LOC_EXTERIOR_IP
=1.1.1.1
16 REM_INTERIOR_IP
=192.168.2.1
17 REM_EXTERIOR_IP
=2.2.2.2
18 REM_INSIDE_NET
=192.168.2.0
21 # Create the interface node ``ng0'' if it doesn't exist already,
22 # otherwise just make sure it's not connected to anything.
23 # In FreeBSD, interfaces cannot be removed so it might already
24 # be there from before.
26 if ifconfig ng0
>/dev
/null
2>&1; then
27 ifconfig ng0 inet down delete
>/dev
/null
2>&1
30 ngctl mkpeer iface dummy inet
33 # Attach a UDP socket to the ``inet'' hook of the interface node
34 # using the ng_ksocket(4) node type.
36 ngctl mkpeer ng0
: ksocket inet inet
/dgram
/udp
38 # Bind the UDP socket to the local external IP address and port
40 ngctl msg ng0
:inet
bind inet
/${LOC_EXTERIOR_IP}:${UDP_TUNNEL_PORT}
42 # Connect the UDP socket to the peer's external IP address and port
44 ngctl msg ng0
:inet connect inet
/${REM_EXTERIOR_IP}:${UDP_TUNNEL_PORT}
46 # Configure the point-to-point interface
48 ifconfig ng0
${LOC_INTERIOR_IP} ${REM_INTERIOR_IP}
50 # Add a route to the peer's interior network via the tunnel
52 route add
${REM_INSIDE_NET} ${REM_INTERIOR_IP}