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:

85683

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-06-08
coredns - 1.14.3
Ebuild name:

net-dns/coredns-1.14.3

Description

CoreDNS is a DNS server that chains plugins

Added to portage

2026-06-08

2026-06-07
ParmEd - 4.3.1
Ebuild name:

sci-chemistry/ParmEd-4.3.1

Description

Parameter and topology file editor and molecular mechanical simulator en

Added to portage

2026-06-07

flask-cors - 6.0.3
Ebuild name:

dev-python/flask-cors-6.0.3

Description

A Flask extension for Cross Origin Resource Sharing (CORS)

Added to portage

2026-06-07

gap - 4.16.0
Ebuild name:

sci-mathematics/gap-4.16.0

Description

System for computational discrete algebra (core functionality)

Added to portage

2026-06-07

gcc - 15.2.1_p20260605
Ebuild name:

sys-devel/gcc-15.2.1_p20260605

Description

The GNU Compiler Collection

Added to portage

2026-06-07

gcc - 16.1.1_p20260606
Ebuild name:

sys-devel/gcc-16.1.1_p20260606

Description

The GNU Compiler Collection

Added to portage

2026-06-07

gopls - 0.22.0
Ebuild name:

dev-go/gopls-0.22.0

Description

Added to portage

2026-06-07

highs - 1.14.0-r3
Ebuild name:

sci-mathematics/highs-1.14.0-r3

Description

Modern solver for linear, quadratic, and mixed-integer programs

Added to portage

2026-06-07

hydrus - 670
Ebuild name:

media-gfx/hydrus-670

Description

A booru-like media organizer for the desktop

Added to portage

2026-06-07

kid3 - 3.10.0
Ebuild name:

media-sound/kid3-3.10.0

Description

Simple tag editor based on Qt

Added to portage

2026-06-07

kitty - 0.47.2
Ebuild name:

x11-terms/kitty-0.47.2

Description

Fast, feature-rich, GPU-based terminal

Added to portage

2026-06-07

kitty-shell-integration - 0.47.2
Ebuild name:

x11-terms/kitty-shell-integration-0.47.2

Description

Shell integration scripts for kitty, a GPU-based terminal

Added to portage

2026-06-07

kitty-terminfo - 0.47.2
Ebuild name:

x11-terms/kitty-terminfo-0.47.2

Description

Terminfo for kitty, a GPU-based terminal emulator

Added to portage

2026-06-07

less - 704
Ebuild name:

sys-apps/less-704

Description

Excellent text file viewer

Added to portage

2026-06-07

logrotate - 3.22.0-r1
Ebuild name:

app-admin/logrotate-3.22.0-r1

Description

Rotates, compresses, and mails system logs

Added to portage

2026-06-07

logrotate - 9999
Ebuild name:

app-admin/logrotate-9999

Description

Rotates, compresses, and mails system logs

Added to portage

2026-06-07

mapserver - 8.6.4
Ebuild name:

sci-geosciences/mapserver-8.6.4

Description

Development environment for building spatially enabled webapps

Added to portage

2026-06-07

markdown-mode - 2.8
Ebuild name:

app-emacs/markdown-mode-2.8

Description

Major mode for editing Markdown-formatted text files

Added to portage

2026-06-07

mastodon - 2.0.7
Ebuild name:

app-emacs/mastodon-2.0.7

Description

Emacs client for Mastodon, federated microblogging social network

Added to portage

2026-06-07

moto - 5.2.2
Ebuild name:

dev-python/moto-5.2.2

Description

Mock library for boto

Added to portage

2026-06-07

mutter - 49.6
Ebuild name:

x11-wm/mutter-49.6

Description

GNOME compositing window manager based on Clutter

Added to portage

2026-06-07

phpBB - 3.3.17
Ebuild name:

www-apps/phpBB-3.3.17

Description

An open-source PHP-based bulletin board package

Added to portage

2026-06-07

plplot - 5.15.0_p15-r2
Ebuild name:

sci-libs/plplot-5.15.0_p15-r2

Description

Multi-language scientific plotting library

Added to portage

2026-06-07

propka - 3.5.1-r1
Ebuild name:

sci-chemistry/propka-3.5.1-r1

Description

pKa-value prediction of ionizable groups in protein and protein-ligan

Added to portage

2026-06-07

protobuf-go - 1.36.11
Ebuild name:

dev-go/protobuf-go-1.36.11

Description

Go support for Google's protocol buffers

Added to portage

2026-06-07

pysam - 0.24.0
Ebuild name:

sci-biology/pysam-0.24.0

Description

Python interface for the SAM/BAM sequence alignment and mapping format

Added to portage

2026-06-07

pysiril - 0.0.17
Ebuild name:

sci-astronomy/pysiril-0.0.17

Description

Python library to interface Python to a SiriL script

Added to portage

2026-06-07

rebar - 3.27.0
Ebuild name:

dev-util/rebar-3.27.0

Description

A sophisticated build-tool for Erlang projects that follows OTP principles

Added to portage

2026-06-07

sh - 2.2.4
Ebuild name:

dev-python/sh-2.2.4

Description

Python subprocess interface

Added to portage

2026-06-07

shotwell - 0.32.16
Ebuild name:

media-gfx/shotwell-0.32.16

Description

Open source photo manager for GNOME

Added to portage

2026-06-07

soundfile - 0.14.0
Ebuild name:

dev-python/soundfile-0.14.0

Description

audio library based on libsndfile, CFFI and NumPy

Added to portage

2026-06-07

structlog - 26.1.0
Ebuild name:

dev-python/structlog-26.1.0

Description

Structured Logging for Python

Added to portage

2026-06-07

zensical - 0.0.41
Ebuild name:

dev-python/zensical-0.0.41

Description

A modern static site generator by the Material for MkDocs team

Added to portage

2026-06-07

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