1#!/bin/sh 2# $FreeBSD: src/share/examples/netgraph/udp.tunnel,v 1.1 2000/01/28 00:44:30 archie Exp $ 3# $DragonFly: src/share/examples/netgraph/udp.tunnel,v 1.2 2003/06/17 04:36:57 dillon Exp $ 4 5# This script sets up a virtual point-to-point WAN link between 6# two subnets, using UDP packets as the ``WAN connection.'' 7# The two subnets might be non-routable addresses behind a 8# firewall. 9# 10 11# Here define the local and remote inside networks as well 12# as the local and remote outside IP addresses and UDP port 13# number that will be used for the tunnel. 14# 15LOC_INTERIOR_IP=192.168.1.1 16LOC_EXTERIOR_IP=1.1.1.1 17REM_INTERIOR_IP=192.168.2.1 18REM_EXTERIOR_IP=2.2.2.2 19REM_INSIDE_NET=192.168.2.0 20UDP_TUNNEL_PORT=4028 21 22# Create the interface node ``ng0'' if it doesn't exist already, 23# otherwise just make sure it's not connected to anything. 24# In FreeBSD, interfaces cannot be removed so it might already 25# be there from before. 26# 27if ifconfig ng0 >/dev/null 2>&1; then 28 ifconfig ng0 inet down delete >/dev/null 2>&1 29 ngctl shutdown ng0: 30else 31 ngctl mkpeer iface dummy inet 32fi 33 34# Attach a UDP socket to the ``inet'' hook of the interface node 35# using the ng_ksocket(8) node type. 36# 37ngctl mkpeer ng0: ksocket inet inet/dgram/udp 38 39# Bind the UDP socket to the local external IP address and port 40# 41ngctl msg ng0:inet bind inet/${LOC_EXTERIOR_IP}:${UDP_TUNNEL_PORT} 42 43# Connect the UDP socket to the peer's external IP address and port 44# 45ngctl msg ng0:inet connect inet/${REM_EXTERIOR_IP}:${UDP_TUNNEL_PORT} 46 47# Configure the point-to-point interface 48# 49ifconfig ng0 ${LOC_INTERIOR_IP} ${REM_INTERIOR_IP} 50 51# Add a route to the peer's interior network via the tunnel 52# 53route add ${REM_INSIDE_NET} ${REM_INTERIOR_IP} 54 55