Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 01-05-2018, 01:47 PM   #1
LQ Newbie
Registered: Jan 2018
Distribution: Arch, Ubuntu Server
Posts: 2

Rep: Reputation: Disabled
Connect via LAN if possible, VPN otherwise


I have an OpenVPN server on my Arch Linux PC (let's call it the Server). Other machines, such as my laptop, are clients and have the desktop's VPN IP address aliased in their own /etc/hosts. The Server's VPN port is port-forwarded by our home router, exposing the VPN port to the Internet.

Here is the problem: When I'm using my laptop at home, I want to access the Server via LAN ( instead of In other words, I need to dynamically look up an IP from a host name, so that all my backup scripts etc. automatically uses LAN when available.

Alternatives that I've pondered:
1) Having my own DNS server (e.g. running BIND on the Server). This feels a bit heavy-handed, but could be done. It doesn't make me warm inside thinking about configuring that thing, but still...

2) Reading up on mDNS / Avahi - perhaps there's a better solution in there.

3) Having the clients forward all traffic to/from the TUN interface to the NIC if the client detects the LAN. /etc/hosts still points to the VPN address. Iptables should be sufficient for this.

I'd appreciate any pointers to documentation / forum posts, if this is a pattern that as a name that I can google (networking design patterns? ), and any other information to get me started.

(I'm also hoping that the solution I go for will let me have the names of my computers centrally configured, instead of putting them in the /etc/hosts file in all my computers, but that's not the priority right now.)

Thanks in advance!

Last edited by Tampopo; 01-05-2018 at 01:53 PM.
Old 01-13-2018, 03:40 AM   #2
LQ Guru
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,734

Rep: Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126Reputation: 1126
Welcome to I think the simplest solution would be to configure your openVPN server so that the clients are assigned 192.168.0.x addresses, as they would be if connected directly to the LAN. There are two ways to do this: a) either using the 'server-bridge directive such that a portion of the DHCP range is used for connecting clients, or b) configure so that clients get IP address leases from the DHCP server (router) which is serving the LAN. Explained here in detail:

FWIW, the corporate network I connect to remotely via VPN uses the latter approach.
1 members found this post helpful.
Old 01-13-2018, 06:22 PM   #3
LQ Newbie
Registered: Jan 2018
Distribution: Arch, Ubuntu Server
Posts: 2

Original Poster
Rep: Reputation: Disabled
That is very helpful, I will give this approach a try. Thank you!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote connection problem(build a separated lan in two VPN connected lan) William17 Linux - Networking 0 12-04-2011 01:33 AM
IPTABLES: Forward from VPN to LAN, Need traffic to appear as if its coming from LAN. a2brute Linux - Networking 3 11-17-2008 11:53 AM
PPTP VPN cant connect to Lan Spunky Linux - Networking 10 10-17-2008 09:18 AM
sharing VPN access with lan + after vpn connected unable to ping lan/public ip xxx_anuj_xxx Linux - Networking 1 03-14-2008 02:50 AM
No Internet but LAN and VPN connect LAN work fine??? xavior SUSE / openSUSE 7 11-09-2005 01:14 PM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:15 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration