How to forward one local network via VPN and another one directly?Using DD-WRT to connect to VPN and Forward all traffic of certain devices through VPNRouting only some local IPs through VPN on dd-wrtN2N VPN + Client VPN - recommended technology and network architecture?Route outbound connections from local network through VPNRoute a specific user's traffic via VPN but still allow local networkingSetting up a server that routes local traffic through vpn, while still being able to access internet directlyHow do I troubleshoot a VPN connection that won't forward DNS requests?Iptables + NAT and port forward loop with one network interfaceiptables: rules to forward incoming packets from a static IP on one interface to a dynamic IP on another interfaceHow to route specific VPN traffic via specific VPN client?
In a Latex Table, how can I automatically resize cell heights to account for superscripts?
Would glacier 'trees' be plausible?
Which industry am I working in? Software development or financial services?
Should one double the thirds or the fifth in chords?
How do I tell my manager that his code review comment is wrong?
Can fracking help reduce CO2?
How to improve/restore vintage Peugeot bike, or is it even worth it?
What happens to the Time Stone
CRT Oscilloscope - part of the plot is missing
Can the 歳 counter be used for architecture, furniture etc to tell its age?
Was Unix ever a single-user OS?
Identifying my late father's D&D stuff found in the attic
SQL Server Management Studio SSMS 18.0 General Availability release (GA) install fails
What are the spoon bit of a spoon and fork bit of a fork called?
Moving the subject of the sentence into a dangling participle
Identifying a transmission to myself
What was the state of the German rail system in 1944?
Can I get a paladin's steed by True Polymorphing into a monster that can cast Find Steed?
Number of seconds in 6 weeks
Why is C# in the D Major Scale?
What is a "listed natural gas appliance"?
Do I really need diodes to receive MIDI?
Would a 1/1 token with persist dying trigger on death effects a second time?
Why is B♯ higher than C♭ in 31-ET?
How to forward one local network via VPN and another one directly?
Using DD-WRT to connect to VPN and Forward all traffic of certain devices through VPNRouting only some local IPs through VPN on dd-wrtN2N VPN + Client VPN - recommended technology and network architecture?Route outbound connections from local network through VPNRoute a specific user's traffic via VPN but still allow local networkingSetting up a server that routes local traffic through vpn, while still being able to access internet directlyHow do I troubleshoot a VPN connection that won't forward DNS requests?Iptables + NAT and port forward loop with one network interfaceiptables: rules to forward incoming packets from a static IP on one interface to a dynamic IP on another interfaceHow to route specific VPN traffic via specific VPN client?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have CentOS Linux 6 based software router. I have 2 local networks, lets say Local1
and Local2
. I have one Internet connection, and I have VPN connection that I run via this Internet one.
I use iptables
and DHCP server to share Internet connection. When I enable VPN, both Local1
and Local2
traffic goes through VPN, without VPN both local networks go directly to Internet.
My question follows: how to set up CentOS based software router to forward one local network via VPN and another one directly?
linux centos iptables routing openvpn
add a comment |
I have CentOS Linux 6 based software router. I have 2 local networks, lets say Local1
and Local2
. I have one Internet connection, and I have VPN connection that I run via this Internet one.
I use iptables
and DHCP server to share Internet connection. When I enable VPN, both Local1
and Local2
traffic goes through VPN, without VPN both local networks go directly to Internet.
My question follows: how to set up CentOS based software router to forward one local network via VPN and another one directly?
linux centos iptables routing openvpn
add a comment |
I have CentOS Linux 6 based software router. I have 2 local networks, lets say Local1
and Local2
. I have one Internet connection, and I have VPN connection that I run via this Internet one.
I use iptables
and DHCP server to share Internet connection. When I enable VPN, both Local1
and Local2
traffic goes through VPN, without VPN both local networks go directly to Internet.
My question follows: how to set up CentOS based software router to forward one local network via VPN and another one directly?
linux centos iptables routing openvpn
I have CentOS Linux 6 based software router. I have 2 local networks, lets say Local1
and Local2
. I have one Internet connection, and I have VPN connection that I run via this Internet one.
I use iptables
and DHCP server to share Internet connection. When I enable VPN, both Local1
and Local2
traffic goes through VPN, without VPN both local networks go directly to Internet.
My question follows: how to set up CentOS based software router to forward one local network via VPN and another one directly?
linux centos iptables routing openvpn
linux centos iptables routing openvpn
asked Aug 15 '16 at 14:59
VitaliyVitaliy
1017
1017
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
I can't tell you how... but I can tell you theoretically.
Most likely, your VPN consists of only a specific network (or set of networks). You would want to set up Split Tunneling to say in Pseudo: "Any traffic destined for 'VPN network,' go through VPN Connection." Then your 0.0.0.0 default route would be all set up to go out through the internet connection.
I also believe priority matters. Be sure the route for the VPN Network has a higher priority than your default route.
VPN connection used to anonymize Internet access in this software router; it is created to access Internet, not the resources inside the VPN. So, we can not route traffic based on its destination; we have to route it based on source, it is what I don't know how to do.
– Vitaliy
Aug 15 '16 at 19:05
add a comment |
First you have to change VPN configuration to not setup itself as a default gateway. What VPN is this?
Second you have to add iptables rule to forward traffic from Local2(eth0) to VPN(tun0)
ex.commands: iptables -I FORWARD -i eth0 -o tun0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
and second
iptables -t nat -I POSTROUTING -o tun0 -s 192.168.0.0/24 -j MASQUERADE
My VPN isOpenVPN
(from offficial CentOS repository). About these rules, may you explain how they will work? So, the first rule, we just allow forwardingeth0
totun0
(but we don't force, so if default root is direct Internet connection and not VPN, how can we guarantee thatiptables
will use this rule?) 2nd rule is required to share connection, no questions. I think that the 1st rule will simply be ignored by router.
– Vitaliy
Aug 16 '16 at 5:26
If its Openvpn working as client the probably is getting directiveredirect-gateway
and set default route to vpn tunnel. Then indeed you have to make static routes for your both local networks.
– Jakub Pisarczyk
Aug 18 '16 at 13:38
add a comment |
Finally I found a way. It is required to use iproute2
, but some not obvious things are present.
- Use
ip rule
to create source-based routing policy. - Use
ip route .... table
to add 3 routs to source-based routing policy: one that sets Internet default gateway, and 2 ones that set gateways for both local networks. It doesn't work without local networks gateways setup, probably because OpenVPN makes a lot of changes in routing table. - Important:
ip rule
andip route
don't persist, so the rules disappear on reboot. It is common to userule-interface
androute-interface
files to set static routes. However, these files are problematic when you use them with DHCP and/or Wi-Fi hotspot. The reason is that these files are applied in parallel to (so some times before) DHCP andhostapd
initialization. That is why these 2 files result in incorrect routing table often. I userc.local
to add routes and rules with command line on system startup instead, and with this approach I am able to route one local NIC via VPN and another one directly.
add a comment |
You need to use VPN without default gateway defined, so all your traffic will goes through old default gateway.
Then you can add the static route which will forward traffic to the local1 subnet to the VPN gateway.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f796904%2fhow-to-forward-one-local-network-via-vpn-and-another-one-directly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
I can't tell you how... but I can tell you theoretically.
Most likely, your VPN consists of only a specific network (or set of networks). You would want to set up Split Tunneling to say in Pseudo: "Any traffic destined for 'VPN network,' go through VPN Connection." Then your 0.0.0.0 default route would be all set up to go out through the internet connection.
I also believe priority matters. Be sure the route for the VPN Network has a higher priority than your default route.
VPN connection used to anonymize Internet access in this software router; it is created to access Internet, not the resources inside the VPN. So, we can not route traffic based on its destination; we have to route it based on source, it is what I don't know how to do.
– Vitaliy
Aug 15 '16 at 19:05
add a comment |
I can't tell you how... but I can tell you theoretically.
Most likely, your VPN consists of only a specific network (or set of networks). You would want to set up Split Tunneling to say in Pseudo: "Any traffic destined for 'VPN network,' go through VPN Connection." Then your 0.0.0.0 default route would be all set up to go out through the internet connection.
I also believe priority matters. Be sure the route for the VPN Network has a higher priority than your default route.
VPN connection used to anonymize Internet access in this software router; it is created to access Internet, not the resources inside the VPN. So, we can not route traffic based on its destination; we have to route it based on source, it is what I don't know how to do.
– Vitaliy
Aug 15 '16 at 19:05
add a comment |
I can't tell you how... but I can tell you theoretically.
Most likely, your VPN consists of only a specific network (or set of networks). You would want to set up Split Tunneling to say in Pseudo: "Any traffic destined for 'VPN network,' go through VPN Connection." Then your 0.0.0.0 default route would be all set up to go out through the internet connection.
I also believe priority matters. Be sure the route for the VPN Network has a higher priority than your default route.
I can't tell you how... but I can tell you theoretically.
Most likely, your VPN consists of only a specific network (or set of networks). You would want to set up Split Tunneling to say in Pseudo: "Any traffic destined for 'VPN network,' go through VPN Connection." Then your 0.0.0.0 default route would be all set up to go out through the internet connection.
I also believe priority matters. Be sure the route for the VPN Network has a higher priority than your default route.
answered Aug 15 '16 at 15:08
PCFixerGuyPCFixerGuy
415
415
VPN connection used to anonymize Internet access in this software router; it is created to access Internet, not the resources inside the VPN. So, we can not route traffic based on its destination; we have to route it based on source, it is what I don't know how to do.
– Vitaliy
Aug 15 '16 at 19:05
add a comment |
VPN connection used to anonymize Internet access in this software router; it is created to access Internet, not the resources inside the VPN. So, we can not route traffic based on its destination; we have to route it based on source, it is what I don't know how to do.
– Vitaliy
Aug 15 '16 at 19:05
VPN connection used to anonymize Internet access in this software router; it is created to access Internet, not the resources inside the VPN. So, we can not route traffic based on its destination; we have to route it based on source, it is what I don't know how to do.
– Vitaliy
Aug 15 '16 at 19:05
VPN connection used to anonymize Internet access in this software router; it is created to access Internet, not the resources inside the VPN. So, we can not route traffic based on its destination; we have to route it based on source, it is what I don't know how to do.
– Vitaliy
Aug 15 '16 at 19:05
add a comment |
First you have to change VPN configuration to not setup itself as a default gateway. What VPN is this?
Second you have to add iptables rule to forward traffic from Local2(eth0) to VPN(tun0)
ex.commands: iptables -I FORWARD -i eth0 -o tun0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
and second
iptables -t nat -I POSTROUTING -o tun0 -s 192.168.0.0/24 -j MASQUERADE
My VPN isOpenVPN
(from offficial CentOS repository). About these rules, may you explain how they will work? So, the first rule, we just allow forwardingeth0
totun0
(but we don't force, so if default root is direct Internet connection and not VPN, how can we guarantee thatiptables
will use this rule?) 2nd rule is required to share connection, no questions. I think that the 1st rule will simply be ignored by router.
– Vitaliy
Aug 16 '16 at 5:26
If its Openvpn working as client the probably is getting directiveredirect-gateway
and set default route to vpn tunnel. Then indeed you have to make static routes for your both local networks.
– Jakub Pisarczyk
Aug 18 '16 at 13:38
add a comment |
First you have to change VPN configuration to not setup itself as a default gateway. What VPN is this?
Second you have to add iptables rule to forward traffic from Local2(eth0) to VPN(tun0)
ex.commands: iptables -I FORWARD -i eth0 -o tun0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
and second
iptables -t nat -I POSTROUTING -o tun0 -s 192.168.0.0/24 -j MASQUERADE
My VPN isOpenVPN
(from offficial CentOS repository). About these rules, may you explain how they will work? So, the first rule, we just allow forwardingeth0
totun0
(but we don't force, so if default root is direct Internet connection and not VPN, how can we guarantee thatiptables
will use this rule?) 2nd rule is required to share connection, no questions. I think that the 1st rule will simply be ignored by router.
– Vitaliy
Aug 16 '16 at 5:26
If its Openvpn working as client the probably is getting directiveredirect-gateway
and set default route to vpn tunnel. Then indeed you have to make static routes for your both local networks.
– Jakub Pisarczyk
Aug 18 '16 at 13:38
add a comment |
First you have to change VPN configuration to not setup itself as a default gateway. What VPN is this?
Second you have to add iptables rule to forward traffic from Local2(eth0) to VPN(tun0)
ex.commands: iptables -I FORWARD -i eth0 -o tun0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
and second
iptables -t nat -I POSTROUTING -o tun0 -s 192.168.0.0/24 -j MASQUERADE
First you have to change VPN configuration to not setup itself as a default gateway. What VPN is this?
Second you have to add iptables rule to forward traffic from Local2(eth0) to VPN(tun0)
ex.commands: iptables -I FORWARD -i eth0 -o tun0 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
and second
iptables -t nat -I POSTROUTING -o tun0 -s 192.168.0.0/24 -j MASQUERADE
answered Aug 15 '16 at 22:16
Jakub PisarczykJakub Pisarczyk
1
1
My VPN isOpenVPN
(from offficial CentOS repository). About these rules, may you explain how they will work? So, the first rule, we just allow forwardingeth0
totun0
(but we don't force, so if default root is direct Internet connection and not VPN, how can we guarantee thatiptables
will use this rule?) 2nd rule is required to share connection, no questions. I think that the 1st rule will simply be ignored by router.
– Vitaliy
Aug 16 '16 at 5:26
If its Openvpn working as client the probably is getting directiveredirect-gateway
and set default route to vpn tunnel. Then indeed you have to make static routes for your both local networks.
– Jakub Pisarczyk
Aug 18 '16 at 13:38
add a comment |
My VPN isOpenVPN
(from offficial CentOS repository). About these rules, may you explain how they will work? So, the first rule, we just allow forwardingeth0
totun0
(but we don't force, so if default root is direct Internet connection and not VPN, how can we guarantee thatiptables
will use this rule?) 2nd rule is required to share connection, no questions. I think that the 1st rule will simply be ignored by router.
– Vitaliy
Aug 16 '16 at 5:26
If its Openvpn working as client the probably is getting directiveredirect-gateway
and set default route to vpn tunnel. Then indeed you have to make static routes for your both local networks.
– Jakub Pisarczyk
Aug 18 '16 at 13:38
My VPN is
OpenVPN
(from offficial CentOS repository). About these rules, may you explain how they will work? So, the first rule, we just allow forwarding eth0
to tun0
(but we don't force, so if default root is direct Internet connection and not VPN, how can we guarantee that iptables
will use this rule?) 2nd rule is required to share connection, no questions. I think that the 1st rule will simply be ignored by router.– Vitaliy
Aug 16 '16 at 5:26
My VPN is
OpenVPN
(from offficial CentOS repository). About these rules, may you explain how they will work? So, the first rule, we just allow forwarding eth0
to tun0
(but we don't force, so if default root is direct Internet connection and not VPN, how can we guarantee that iptables
will use this rule?) 2nd rule is required to share connection, no questions. I think that the 1st rule will simply be ignored by router.– Vitaliy
Aug 16 '16 at 5:26
If its Openvpn working as client the probably is getting directive
redirect-gateway
and set default route to vpn tunnel. Then indeed you have to make static routes for your both local networks.– Jakub Pisarczyk
Aug 18 '16 at 13:38
If its Openvpn working as client the probably is getting directive
redirect-gateway
and set default route to vpn tunnel. Then indeed you have to make static routes for your both local networks.– Jakub Pisarczyk
Aug 18 '16 at 13:38
add a comment |
Finally I found a way. It is required to use iproute2
, but some not obvious things are present.
- Use
ip rule
to create source-based routing policy. - Use
ip route .... table
to add 3 routs to source-based routing policy: one that sets Internet default gateway, and 2 ones that set gateways for both local networks. It doesn't work without local networks gateways setup, probably because OpenVPN makes a lot of changes in routing table. - Important:
ip rule
andip route
don't persist, so the rules disappear on reboot. It is common to userule-interface
androute-interface
files to set static routes. However, these files are problematic when you use them with DHCP and/or Wi-Fi hotspot. The reason is that these files are applied in parallel to (so some times before) DHCP andhostapd
initialization. That is why these 2 files result in incorrect routing table often. I userc.local
to add routes and rules with command line on system startup instead, and with this approach I am able to route one local NIC via VPN and another one directly.
add a comment |
Finally I found a way. It is required to use iproute2
, but some not obvious things are present.
- Use
ip rule
to create source-based routing policy. - Use
ip route .... table
to add 3 routs to source-based routing policy: one that sets Internet default gateway, and 2 ones that set gateways for both local networks. It doesn't work without local networks gateways setup, probably because OpenVPN makes a lot of changes in routing table. - Important:
ip rule
andip route
don't persist, so the rules disappear on reboot. It is common to userule-interface
androute-interface
files to set static routes. However, these files are problematic when you use them with DHCP and/or Wi-Fi hotspot. The reason is that these files are applied in parallel to (so some times before) DHCP andhostapd
initialization. That is why these 2 files result in incorrect routing table often. I userc.local
to add routes and rules with command line on system startup instead, and with this approach I am able to route one local NIC via VPN and another one directly.
add a comment |
Finally I found a way. It is required to use iproute2
, but some not obvious things are present.
- Use
ip rule
to create source-based routing policy. - Use
ip route .... table
to add 3 routs to source-based routing policy: one that sets Internet default gateway, and 2 ones that set gateways for both local networks. It doesn't work without local networks gateways setup, probably because OpenVPN makes a lot of changes in routing table. - Important:
ip rule
andip route
don't persist, so the rules disappear on reboot. It is common to userule-interface
androute-interface
files to set static routes. However, these files are problematic when you use them with DHCP and/or Wi-Fi hotspot. The reason is that these files are applied in parallel to (so some times before) DHCP andhostapd
initialization. That is why these 2 files result in incorrect routing table often. I userc.local
to add routes and rules with command line on system startup instead, and with this approach I am able to route one local NIC via VPN and another one directly.
Finally I found a way. It is required to use iproute2
, but some not obvious things are present.
- Use
ip rule
to create source-based routing policy. - Use
ip route .... table
to add 3 routs to source-based routing policy: one that sets Internet default gateway, and 2 ones that set gateways for both local networks. It doesn't work without local networks gateways setup, probably because OpenVPN makes a lot of changes in routing table. - Important:
ip rule
andip route
don't persist, so the rules disappear on reboot. It is common to userule-interface
androute-interface
files to set static routes. However, these files are problematic when you use them with DHCP and/or Wi-Fi hotspot. The reason is that these files are applied in parallel to (so some times before) DHCP andhostapd
initialization. That is why these 2 files result in incorrect routing table often. I userc.local
to add routes and rules with command line on system startup instead, and with this approach I am able to route one local NIC via VPN and another one directly.
answered Aug 16 '16 at 11:10
VitaliyVitaliy
1017
1017
add a comment |
add a comment |
You need to use VPN without default gateway defined, so all your traffic will goes through old default gateway.
Then you can add the static route which will forward traffic to the local1 subnet to the VPN gateway.
add a comment |
You need to use VPN without default gateway defined, so all your traffic will goes through old default gateway.
Then you can add the static route which will forward traffic to the local1 subnet to the VPN gateway.
add a comment |
You need to use VPN without default gateway defined, so all your traffic will goes through old default gateway.
Then you can add the static route which will forward traffic to the local1 subnet to the VPN gateway.
You need to use VPN without default gateway defined, so all your traffic will goes through old default gateway.
Then you can add the static route which will forward traffic to the local1 subnet to the VPN gateway.
answered Aug 25 '16 at 16:01
Tim ConnorTim Connor
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f796904%2fhow-to-forward-one-local-network-via-vpn-and-another-one-directly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown