From Gentoo Linux Wiki
[edit] Introduction
The following script will let you start a full featured VPN using SSH and tun.
[edit] Requirements
- OpenSSH with tun support on both sides (tested Debian 4.3 on server, Gentoo 4.5 on client)
- Root access on both sides
- Allowed root access and tunnel on server side:
| File: /etc/ssh/sshd_config
|
|
|
- Compiled ‘tun’ module on both sides
- Loaded ‘tun’ module on server side
- Allowed ARP proxy (required only for accessing client from within the private network)
[edit] The script
[edit] Configuration
The following configuration can be set at the beginning of the script:
| Item | Description
|
| HOST | Hostname of the remote SSH server (either IP or DNS name).
|
| HOST_PORT | Host port of the remote ssh server (default: 22)
|
| TUN_LOCAL | Number of local tun interface. You cannot use ‘any’.
|
| TUN_REMOTE | Number of remote tun interface. You cannot use ‘any’.
|
| IP_LOCAL | IP address of local tun interface.
|
| IP_REMOTE | IP address of server tun interface.
|
| IP_MASK | IP address mask of the tuns.
|
| PRIVATE_NETWORK | Network specification (any of its IP addresses and mask) of the private network.
|
| PRIVATE_DOMAIN | Space delimiteed list of domain names of the private network (if any).
|
| PRIVATE_NAMESERVER | Nameserver in the private network.
|
| PRIVATE_LOCAL | IP address in the private network that uses this computer (in order to allow access from the private network).
|
- Convert to init.d script (ie. create stop script)
- Detect failure
- On close clear the server’s iptables and restore local ‘/etc/resolv.conf’
- More secure access with ‘sudo’ instead of root access on server side
- Allow using first unused tun interface (‘any’)