from small one page howto to huge articles all in one place

search text in:




Other .linuxhowtos.org sites: www.linuxhowtos.org
toolsntoys.linuxhowtos.org



Last additions:
How to make X listen on port 6000

How to make X listen on port 6000

words:

34

views:

88688

userrating:

average rating: 1.2 (52 votes) (1=very good 6=terrible)


May, 25th 2007:
April, 26th 2007:
Apr, 10th. 2007:
Druckversion . pdf icon
You are here: Tutorials per portage category->net-misc->openvpn

OpenVPN primer


There are as many advantages to VPN tunnels as there are different VPN scenarios. One easy implementation is the "OpenVPN via tun-device" solution. An example: you'd like to connect your laptop to your LAN at home so that you can use your mail client without reconfiguring it anytime you switch from home to internet and back. Let's say your mail-server is 192.168.1.10 in your LAN (192.168.1.0/24) at home, and you have got a router/firewall providing access to the Internet. You connect from work or school and want to read mail. OpenVPN can create two virtual devices for you when connecting two computers through an encrypted tunnel. Naturally you then have the possibility of forwarding traffic into the networks behind them, and thus would be "virtually connected" to your LAN behind the firewall. To enable this, either your firewall or a server behind it should run OpenVPN (if you choose a server in your LAN, you'll have to forward the destination port to the OpenVPN server).

Here's what you need to do:
Code Listing 1: Enable the tun module in your kernel: Kernel config - tun module
          [*] Networking support    
Networking options --->
[ ] Amateur Radio support --->
< > IrDA (infrared) subsystem support --->
< > Bluetooth subsystem support --->
[*] Network device support
< > Dummy net driver support
< > Bonding driver support
< > EQL (serial line load balancing) support
Universal TUN/TAP device driver support
// This option must be enabled


Make sure this module exists and can be loaded. Next, install OpenVPN and it dependencies.
Code Listing 2: Install OpenVPN
emerge openvpn

Now on both server and client, create a directory for your configuration:

Code Listing 3: Make directory
mkdir /etc/openvpn    
mkdir /etc/openvpn/myhomelan


Inside that directory, create a shared key for your VPN session and copy that key to the client's directory, /etc/openvpn/myhomelan.

Code Listing 4: Generate shared key
cd /etc/openvpn/myhomelan    
openvpn --genkey --secret myhomelan-key.txt


Now for the tricky part, the routing. It is important that the two tun devices on the client and server use IP addresses from the same subnet. The configuration files shown below list the type of device, the two end-points of the tunnel, the compression method and the UDP-port on which the tunnel is established. Finally privileges are dropped to user and group as listed:

Code Listing 5: Server-side configuration file /etc/openvpn/myhomelan/local.conf
dev tun    
ifconfig 172.16.1.1 172.16.1.20 // IP of the local
// tun device and its peer
secret /etc/openvpn/myhomelan/myhomelan-key.txt
comp-lzo
port 5000
user nobody
group nobody


The client's configuration needs the tunnel's destination address. This is often a dynamic DNS address, sometimes a fixed IP, depending on your ISP. You also need to route to your home LAN (192.168.1.0 in our example). You can call a shell script from the configuration file that accordingly sets a route.

Code Listing 6: Client-side configuration file /etc/openvpn/myhomelan/local.conf
remote    // or your VPN 
// server's external IP if you have a fixed one
dev tun
ifconfig 172.16.1.20 172.16.1.1 // IP of the local tun
// device and its peer
secret /etc/openvpn/myhomelan/myhomelan-key.txt
comp-lzo
port 5000
user nobody
group nobody
up /etc/openvpn/myhomelan/route.sh // sets up the route
//to the network behind the VPN server


The route command would need to set the client's gateway for the network 192.168.1.0 to its peer's address (172.16.1.1 in our setup).

Code Listing 7: /etc/openvpn/myhomelan/route.sh
#!/bin/bash    
route add -net 192.168.1.0 netmask 255.255.255.0 gw 172.16.1.1


That's it. Start OpenVPN on the server and the client, and check the devices with ifconfig and the routes with route -n. Success!

From http://www.gentoo.org/news/en/gwn/20041011-newsletter.xml
rate this article:
current rating: average rating: 1.5 (69 votes) (1=very good 6=terrible)
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back



Support us on Content Nation

New Packages

- as rdf newsfeed
- as rss newsfeed
- as Atom newsfeed
2026-09-26
2026-09-25
awscli - 2.37.2
Ebuild name:

app-admin/awscli-2.37.2

Description

Universal Command Line Environment for AWS

Added to portage

2026-09-25

containerd - 2.4.1
Ebuild name:

app-containers/containerd-2.4.1

Description

A daemon to control runC

Added to portage

2026-09-25

graphviz-dot-mode - 0.4_p20181118
Ebuild name:

app-emacs/graphviz-dot-mode-0.4_p20181118

Description

Emacs mode for editing and previewing Graphviz dot graphs

Added to portage

2026-09-25

groovy-emacs-modes - 2.1
Ebuild name:

app-emacs/groovy-emacs-modes-2.1

Description

Groovy major mode, grails minor mode, and a groovy inferior mode

Added to portage

2026-09-25

gruvbox-theme - 1.30.2
Ebuild name:

app-emacs/gruvbox-theme-1.30.2

Description

Gruvbox is a retro groove color scheme, now in Emacs

Added to portage

2026-09-25

gruvbox-theme - 1.30.3
Ebuild name:

app-emacs/gruvbox-theme-1.30.3

Description

Gruvbox is a retro groove color scheme, now in Emacs

Added to portage

2026-09-25

gruvbox-theme - 9999
Ebuild name:

app-emacs/gruvbox-theme-9999

Description

Gruvbox is a retro groove color scheme, now in Emacs

Added to portage

2026-09-25

h4x0r - 0.13-r1
Ebuild name:

app-emacs/h4x0r-0.13-r1

Description

Aid in writing like a script kiddie does

Added to portage

2026-09-25

haskell-mode - 17.4
Ebuild name:

app-emacs/haskell-mode-17.4

Description

Mode for editing (and running) Haskell programs in Emacs

Added to portage

2026-09-25

linode-cli - 5.69.0
Ebuild name:

app-admin/linode-cli-5.69.0

Description

Official command-line interface for interacting with the Linode API

Added to portage

2026-09-25

magit - 4.7.1
Ebuild name:

app-emacs/magit-4.7.1

Description

A Git porcelain inside Emacs

Added to portage

2026-09-25

package-build - 5.0.3
Ebuild name:

app-emacs/package-build-5.0.3

Description

Tools for assembling a package archive

Added to portage

2026-09-25

pycargoebuild - 0.17.1
Ebuild name:

app-portage/pycargoebuild-0.17.1

Description

A generator for Rust/Cargo ebuilds written in Python

Added to portage

2026-09-25

untangle-https-backup - 0.2.0
Ebuild name:

app-backup/untangle-https-backup-0.2.0

Description

Back up Untangle configurations via the web admin UI

Added to portage

2026-09-25

vertico - 2.15
Ebuild name:

app-emacs/vertico-2.15

Description

Vertical interactive completion

Added to portage

2026-09-25

rdf newsfeed | rss newsfeed | Atom newsfeed
Copyright 2004-2025 Sascha Nitsch Unternehmensberatung GmbH
- Copyright and legal notices -
Time to create this page: 117.4 ms