README.tun 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. How to use OpenSSH-based virtual private networks
  2. -------------------------------------------------
  3. OpenSSH contains support for VPN tunneling using the tun(4) network
  4. tunnel pseudo-device which is available on most platforms, either for
  5. layer 2 or 3 traffic.
  6. The following brief instructions on how to use this feature use
  7. a network configuration specific to the OpenBSD operating system.
  8. (1) Server: Enable support for SSH tunneling
  9. To enable the ssh server to accept tunnel requests from the client, you
  10. have to add the following option to the ssh server configuration file
  11. (/etc/ssh/sshd_config):
  12. PermitTunnel yes
  13. Restart the server or send the hangup signal (SIGHUP) to let the server
  14. reread it's configuration.
  15. (2) Server: Restrict client access and assign the tunnel
  16. The OpenSSH server simply uses the file /root/.ssh/authorized_keys to
  17. restrict the client to connect to a specified tunnel and to
  18. automatically start the related interface configuration command. These
  19. settings are optional but recommended:
  20. tunnel="1",command="sh /etc/netstart tun1" ssh-rsa ... reyk@openbsd.org
  21. (3) Client: Configure the local network tunnel interface
  22. Use the hostname.if(5) interface-specific configuration file to set up
  23. the network tunnel configuration with OpenBSD. For example, use the
  24. following configuration in /etc/hostname.tun0 to set up the layer 3
  25. tunnel on the client:
  26. inet 192.168.5.1 255.255.255.252 192.168.5.2
  27. OpenBSD also supports layer 2 tunneling over the tun device by adding
  28. the link0 flag:
  29. inet 192.168.1.78 255.255.255.0 192.168.1.255 link0
  30. Layer 2 tunnels can be used in combination with an Ethernet bridge(4)
  31. interface, like the following example for /etc/bridgename.bridge0:
  32. add tun0
  33. add sis0
  34. up
  35. (4) Client: Configure the OpenSSH client
  36. To establish tunnel forwarding for connections to a specified
  37. remote host by default, use the following ssh client configuration for
  38. the privileged user (in /root/.ssh/config):
  39. Host sshgateway
  40. Tunnel yes
  41. TunnelDevice 0:any
  42. PermitLocalCommand yes
  43. LocalCommand sh /etc/netstart tun0
  44. A more complicated configuration is possible to establish a tunnel to
  45. a remote host which is not directly accessible by the client.
  46. The following example describes a client configuration to connect to
  47. the remote host over two ssh hops in between. It uses the OpenSSH
  48. ProxyCommand in combination with the nc(1) program to forward the final
  49. ssh tunnel destination over multiple ssh sessions.
  50. Host access.somewhere.net
  51. User puffy
  52. Host dmzgw
  53. User puffy
  54. ProxyCommand ssh access.somewhere.net nc dmzgw 22
  55. Host sshgateway
  56. Tunnel Ethernet
  57. TunnelDevice 0:any
  58. PermitLocalCommand yes
  59. LocalCommand sh /etc/netstart tun0
  60. ProxyCommand ssh dmzgw nc sshgateway 22
  61. The following network plan illustrates the previous configuration in
  62. combination with layer 2 tunneling and Ethernet bridging.
  63. +--------+ ( ) +----------------------+
  64. | Client |------( Internet )-----| access.somewhere.net |
  65. +--------+ ( ) +----------------------+
  66. : 192.168.1.78 |
  67. :............................. +-------+
  68. Forwarded ssh connection : | dmzgw |
  69. Layer 2 tunnel : +-------+
  70. : |
  71. : |
  72. : +------------+
  73. :......| sshgateway |
  74. | +------------+
  75. --- real connection Bridge -> | +----------+
  76. ... "virtual connection" [ X ]--------| somehost |
  77. [X] switch +----------+
  78. 192.168.1.25
  79. (5) Client: Connect to the server and establish the tunnel
  80. Finally connect to the OpenSSH server to establish the tunnel by using
  81. the following command:
  82. ssh sshgateway
  83. It is also possible to tell the client to fork into the background after
  84. the connection has been successfully established:
  85. ssh -f sshgateway true
  86. Without the ssh configuration done in step (4), it is also possible
  87. to use the following command lines:
  88. ssh -fw 0:1 sshgateway true
  89. ifconfig tun0 192.168.5.1 192.168.5.2 netmask 255.255.255.252
  90. Using OpenSSH tunnel forwarding is a simple way to establish secure
  91. and ad hoc virtual private networks. Possible fields of application
  92. could be wireless networks or administrative VPN tunnels.
  93. Nevertheless, ssh tunneling requires some packet header overhead and
  94. runs on top of TCP. It is still suggested to use the IP Security
  95. Protocol (IPSec) for robust and permanent VPN connections and to
  96. interconnect corporate networks.
  97. Reyk Floeter
  98. $OpenBSD: README.tun,v 1.4 2006/03/28 00:12:31 deraadt Exp $