Making a server behind a VPN client remain reachableReply on the same interface as incoming with DNATed IPRoute certain domains through different interfacesSetting up a server that routes local traffic through vpn, while still being able to access internet directlyCan I assign a virtual interface (VPN) to a 'real' interface / NIC of my choice?Linux tun interface packet routingDouble VPN (OpenVPN)connect to 3rd party VPN server but don't use it as the default route?Mikrotik with vpn client doesn't route mangled packets wellHow to connect 3 Openvpn Ubuntu ServersVPN Router does not reply to ARP RequestsDouble VPN client->server->client

What's the safest way to inform a new user of their password on my web site?

How do I reference other list in calculated column?

One folder two different locations on ubuntu 18.04

What is the consensus on handling pagination in 2019 on big result sets?

Quacks of Quedlingburg Crow Skull Set 2 Keep Drawing

Can a single server be associated with multiple domains?

Why won't the ground take my seed?

Why is Madam Hooch not a professor?

What could a reptilian race tell by candling their eggs?

Why transcripts instead of degree certificates?

Zombie diet, why humans?

Most possible movement by the losing side in a zugzwang position

How do accents of a whole town drift?

I am having a problem understanding the different behavior of $("button").click() and $("button")[0].click()

User command to reload file-local variables

How to start learning the piano again

For people who believe in Jesus and not the devil, what happened in the desert?

Getting geometries of hurricane's 'cone of uncertainty' using shapely?

What are good ways to spray paint a QR code on a footpath?

Should the Torah be covered or uncovered during the Aliyah blessings?

What does Mildred mean by this line in Three Billboards Outside Ebbing, Missouri?

Fluently Validation of Objects

What is the olden name for sideburns?

Why are 120V general receptacle circuits limited to 20A?



Making a server behind a VPN client remain reachable


Reply on the same interface as incoming with DNATed IPRoute certain domains through different interfacesSetting up a server that routes local traffic through vpn, while still being able to access internet directlyCan I assign a virtual interface (VPN) to a 'real' interface / NIC of my choice?Linux tun interface packet routingDouble VPN (OpenVPN)connect to 3rd party VPN server but don't use it as the default route?Mikrotik with vpn client doesn't route mangled packets wellHow to connect 3 Openvpn Ubuntu ServersVPN Router does not reply to ARP RequestsDouble VPN client->server->client






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a server used as a Web and SSH server under Linux. There runs a VPN client, with OpenVPN. If I have properly understood, the VPN changes the routing tables, leading to forwarding all the traffic through the VPN.



Then, when I try to request my Web site hosted on the server, it has become unavailable. I have a very primary knowledge in networking, but what I can assume (feel you free to correct me if I am wrong) is that the request is correctly received by the server through the usual interface, let's name it eth0, but given that the route has changed and passes now through the VPN, the response should be sent on the VPN's interface, which is obviously impossible for security sake.



I looked up the following threads:



https://superuser.com/questions/753736/accessing-a-webserver-hosted-behind-vpn-with-closed-ports-remotely



Reply on the same interface as incoming with DNATed IP



https://unix.stackexchange.com/questions/4420/reply-on-same-interface-as-incoming



but unfortunately, they have been unhelpful.



Let's call the VPN's interface tun0. What I would like to do, is to reply to requests on eth0 on the same interface, namely eth0 itself, instead of tun0 as the VPN runs. Another precision, my server is behind a gateway which is different from it (two different IP addresses).



1) Is it possible to do so?



2) What are the different ways to do that?



Thank you in advance for your feedback.










share|improve this question



















  • 1





    It is posssible to do such a setup. The question is, what is the purpose of the VPN and which traffic (e.g. destination range) needs to be routed through the VPN tunnel. In such situation I'd try to only route the needed traffic through the tunnel.

    – hargut
    Jun 8 at 18:03











  • The server is also a PC. I would like to route the browsers and torrent's traffic through the VPN tunnel, while not tunneling the traffic pertaining to server activities.

    – Moth
    Jun 8 at 18:30






  • 1





    So, in your situation it might be easier to only guide server traffic through eth0. Does the server need to be reachable through vpn inbound traffic?

    – hargut
    Jun 8 at 20:31











  • For now, no, it does not. 1) How can we do that, namely guiding the server traffic through eth0? 2) But concerning what you pointed out, I wanted to know how to make my server reachable through the VPN inbound traffic, what would be the way to do that please?

    – Moth
    Jun 8 at 21:44






  • 1





    It is hatd to make any suggestion as there are still too little details on the setup available. The directions could be 1) setup iptable rules that match servers traffic (e.g. source port) and specify the output device device. 2) setup vpn in a routed mode, set iptable rules that match the vpn cidrs and the server traffic, specify the output device tun0. If you have WAN inbound server traffic through VPN it will be more complex. Full details for such setups are not someting that I will do in a serverfault comment. There are too many factors and too little time to explain/clarify all of these.

    – hargut
    Jun 9 at 6:22

















0















I have a server used as a Web and SSH server under Linux. There runs a VPN client, with OpenVPN. If I have properly understood, the VPN changes the routing tables, leading to forwarding all the traffic through the VPN.



Then, when I try to request my Web site hosted on the server, it has become unavailable. I have a very primary knowledge in networking, but what I can assume (feel you free to correct me if I am wrong) is that the request is correctly received by the server through the usual interface, let's name it eth0, but given that the route has changed and passes now through the VPN, the response should be sent on the VPN's interface, which is obviously impossible for security sake.



I looked up the following threads:



https://superuser.com/questions/753736/accessing-a-webserver-hosted-behind-vpn-with-closed-ports-remotely



Reply on the same interface as incoming with DNATed IP



https://unix.stackexchange.com/questions/4420/reply-on-same-interface-as-incoming



but unfortunately, they have been unhelpful.



Let's call the VPN's interface tun0. What I would like to do, is to reply to requests on eth0 on the same interface, namely eth0 itself, instead of tun0 as the VPN runs. Another precision, my server is behind a gateway which is different from it (two different IP addresses).



1) Is it possible to do so?



2) What are the different ways to do that?



Thank you in advance for your feedback.










share|improve this question



















  • 1





    It is posssible to do such a setup. The question is, what is the purpose of the VPN and which traffic (e.g. destination range) needs to be routed through the VPN tunnel. In such situation I'd try to only route the needed traffic through the tunnel.

    – hargut
    Jun 8 at 18:03











  • The server is also a PC. I would like to route the browsers and torrent's traffic through the VPN tunnel, while not tunneling the traffic pertaining to server activities.

    – Moth
    Jun 8 at 18:30






  • 1





    So, in your situation it might be easier to only guide server traffic through eth0. Does the server need to be reachable through vpn inbound traffic?

    – hargut
    Jun 8 at 20:31











  • For now, no, it does not. 1) How can we do that, namely guiding the server traffic through eth0? 2) But concerning what you pointed out, I wanted to know how to make my server reachable through the VPN inbound traffic, what would be the way to do that please?

    – Moth
    Jun 8 at 21:44






  • 1





    It is hatd to make any suggestion as there are still too little details on the setup available. The directions could be 1) setup iptable rules that match servers traffic (e.g. source port) and specify the output device device. 2) setup vpn in a routed mode, set iptable rules that match the vpn cidrs and the server traffic, specify the output device tun0. If you have WAN inbound server traffic through VPN it will be more complex. Full details for such setups are not someting that I will do in a serverfault comment. There are too many factors and too little time to explain/clarify all of these.

    – hargut
    Jun 9 at 6:22













0












0








0








I have a server used as a Web and SSH server under Linux. There runs a VPN client, with OpenVPN. If I have properly understood, the VPN changes the routing tables, leading to forwarding all the traffic through the VPN.



Then, when I try to request my Web site hosted on the server, it has become unavailable. I have a very primary knowledge in networking, but what I can assume (feel you free to correct me if I am wrong) is that the request is correctly received by the server through the usual interface, let's name it eth0, but given that the route has changed and passes now through the VPN, the response should be sent on the VPN's interface, which is obviously impossible for security sake.



I looked up the following threads:



https://superuser.com/questions/753736/accessing-a-webserver-hosted-behind-vpn-with-closed-ports-remotely



Reply on the same interface as incoming with DNATed IP



https://unix.stackexchange.com/questions/4420/reply-on-same-interface-as-incoming



but unfortunately, they have been unhelpful.



Let's call the VPN's interface tun0. What I would like to do, is to reply to requests on eth0 on the same interface, namely eth0 itself, instead of tun0 as the VPN runs. Another precision, my server is behind a gateway which is different from it (two different IP addresses).



1) Is it possible to do so?



2) What are the different ways to do that?



Thank you in advance for your feedback.










share|improve this question
















I have a server used as a Web and SSH server under Linux. There runs a VPN client, with OpenVPN. If I have properly understood, the VPN changes the routing tables, leading to forwarding all the traffic through the VPN.



Then, when I try to request my Web site hosted on the server, it has become unavailable. I have a very primary knowledge in networking, but what I can assume (feel you free to correct me if I am wrong) is that the request is correctly received by the server through the usual interface, let's name it eth0, but given that the route has changed and passes now through the VPN, the response should be sent on the VPN's interface, which is obviously impossible for security sake.



I looked up the following threads:



https://superuser.com/questions/753736/accessing-a-webserver-hosted-behind-vpn-with-closed-ports-remotely



Reply on the same interface as incoming with DNATed IP



https://unix.stackexchange.com/questions/4420/reply-on-same-interface-as-incoming



but unfortunately, they have been unhelpful.



Let's call the VPN's interface tun0. What I would like to do, is to reply to requests on eth0 on the same interface, namely eth0 itself, instead of tun0 as the VPN runs. Another precision, my server is behind a gateway which is different from it (two different IP addresses).



1) Is it possible to do so?



2) What are the different ways to do that?



Thank you in advance for your feedback.







networking vpn routing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 10 at 10:31







Moth

















asked Jun 8 at 12:25









MothMoth

255 bronze badges




255 bronze badges







  • 1





    It is posssible to do such a setup. The question is, what is the purpose of the VPN and which traffic (e.g. destination range) needs to be routed through the VPN tunnel. In such situation I'd try to only route the needed traffic through the tunnel.

    – hargut
    Jun 8 at 18:03











  • The server is also a PC. I would like to route the browsers and torrent's traffic through the VPN tunnel, while not tunneling the traffic pertaining to server activities.

    – Moth
    Jun 8 at 18:30






  • 1





    So, in your situation it might be easier to only guide server traffic through eth0. Does the server need to be reachable through vpn inbound traffic?

    – hargut
    Jun 8 at 20:31











  • For now, no, it does not. 1) How can we do that, namely guiding the server traffic through eth0? 2) But concerning what you pointed out, I wanted to know how to make my server reachable through the VPN inbound traffic, what would be the way to do that please?

    – Moth
    Jun 8 at 21:44






  • 1





    It is hatd to make any suggestion as there are still too little details on the setup available. The directions could be 1) setup iptable rules that match servers traffic (e.g. source port) and specify the output device device. 2) setup vpn in a routed mode, set iptable rules that match the vpn cidrs and the server traffic, specify the output device tun0. If you have WAN inbound server traffic through VPN it will be more complex. Full details for such setups are not someting that I will do in a serverfault comment. There are too many factors and too little time to explain/clarify all of these.

    – hargut
    Jun 9 at 6:22












  • 1





    It is posssible to do such a setup. The question is, what is the purpose of the VPN and which traffic (e.g. destination range) needs to be routed through the VPN tunnel. In such situation I'd try to only route the needed traffic through the tunnel.

    – hargut
    Jun 8 at 18:03











  • The server is also a PC. I would like to route the browsers and torrent's traffic through the VPN tunnel, while not tunneling the traffic pertaining to server activities.

    – Moth
    Jun 8 at 18:30






  • 1





    So, in your situation it might be easier to only guide server traffic through eth0. Does the server need to be reachable through vpn inbound traffic?

    – hargut
    Jun 8 at 20:31











  • For now, no, it does not. 1) How can we do that, namely guiding the server traffic through eth0? 2) But concerning what you pointed out, I wanted to know how to make my server reachable through the VPN inbound traffic, what would be the way to do that please?

    – Moth
    Jun 8 at 21:44






  • 1





    It is hatd to make any suggestion as there are still too little details on the setup available. The directions could be 1) setup iptable rules that match servers traffic (e.g. source port) and specify the output device device. 2) setup vpn in a routed mode, set iptable rules that match the vpn cidrs and the server traffic, specify the output device tun0. If you have WAN inbound server traffic through VPN it will be more complex. Full details for such setups are not someting that I will do in a serverfault comment. There are too many factors and too little time to explain/clarify all of these.

    – hargut
    Jun 9 at 6:22







1




1





It is posssible to do such a setup. The question is, what is the purpose of the VPN and which traffic (e.g. destination range) needs to be routed through the VPN tunnel. In such situation I'd try to only route the needed traffic through the tunnel.

– hargut
Jun 8 at 18:03





It is posssible to do such a setup. The question is, what is the purpose of the VPN and which traffic (e.g. destination range) needs to be routed through the VPN tunnel. In such situation I'd try to only route the needed traffic through the tunnel.

– hargut
Jun 8 at 18:03













The server is also a PC. I would like to route the browsers and torrent's traffic through the VPN tunnel, while not tunneling the traffic pertaining to server activities.

– Moth
Jun 8 at 18:30





The server is also a PC. I would like to route the browsers and torrent's traffic through the VPN tunnel, while not tunneling the traffic pertaining to server activities.

– Moth
Jun 8 at 18:30




1




1





So, in your situation it might be easier to only guide server traffic through eth0. Does the server need to be reachable through vpn inbound traffic?

– hargut
Jun 8 at 20:31





So, in your situation it might be easier to only guide server traffic through eth0. Does the server need to be reachable through vpn inbound traffic?

– hargut
Jun 8 at 20:31













For now, no, it does not. 1) How can we do that, namely guiding the server traffic through eth0? 2) But concerning what you pointed out, I wanted to know how to make my server reachable through the VPN inbound traffic, what would be the way to do that please?

– Moth
Jun 8 at 21:44





For now, no, it does not. 1) How can we do that, namely guiding the server traffic through eth0? 2) But concerning what you pointed out, I wanted to know how to make my server reachable through the VPN inbound traffic, what would be the way to do that please?

– Moth
Jun 8 at 21:44




1




1





It is hatd to make any suggestion as there are still too little details on the setup available. The directions could be 1) setup iptable rules that match servers traffic (e.g. source port) and specify the output device device. 2) setup vpn in a routed mode, set iptable rules that match the vpn cidrs and the server traffic, specify the output device tun0. If you have WAN inbound server traffic through VPN it will be more complex. Full details for such setups are not someting that I will do in a serverfault comment. There are too many factors and too little time to explain/clarify all of these.

– hargut
Jun 9 at 6:22





It is hatd to make any suggestion as there are still too little details on the setup available. The directions could be 1) setup iptable rules that match servers traffic (e.g. source port) and specify the output device device. 2) setup vpn in a routed mode, set iptable rules that match the vpn cidrs and the server traffic, specify the output device tun0. If you have WAN inbound server traffic through VPN it will be more complex. Full details for such setups are not someting that I will do in a serverfault comment. There are too many factors and too little time to explain/clarify all of these.

– hargut
Jun 9 at 6:22










1 Answer
1






active

oldest

votes


















2














Finally, to my problematic I found a solution inspired from:



https://lartc.org/howto/lartc.rpdb.multiple-links.html .



Here is how to proceed.



To configure the routing of the server so that it is attainable behind a VPN client, a separate routing table ought to be used to avoid an overlap of routing configurations of the two interfaces.



Let <interface>, <table>, <ip>, <gateway> and <network> be the interface name, the table, the IP address of <interface>, the gateway's IP address, and the IP address of the network (that provided by the ISP), respectively.



The procedure to follow is:



  1. Creation of the specific routing table of <interface>: creating the new table <table> in /etc/iproute2/rt_tables.



  2. Setting a different routing configuration for the interface associated to <gateway> by means of a specific table.



    The traffic towards <network> is associated to the interface <interface> and follows the specific routing table <table>:



    ip route add <network> dev <interface> src <ip> table <table>



    Building a default route via this gateway:



    ip route add default via <gateway> table <table>




  3. On <interface>, forcing the traffic from <ip> passing through <network>, to use the interface <interface>:



    ip route add <network> dev <interface> src <ip>



    The src argument is specified to make sure the right outgoing IP address is chosen.




  4. Associating the interface to the appropriate <network>:



    ip rule add from <ip> table



Key idea:



The key idea to understand, concerning why to use this technique here, is that for any request passing through the ISP node, here <network>, the latter will be an intermediate node of the response's route. This seems obvious, but forgetting it leads to not understand why <network> does matter in the routing configuration of the interface normally used to communicate with the server from outside.



Optional:




  1. Setting the routes for all destinations to pass through <gateway> instead of through the VPN's gateway. Useful when it is needed to use the VPN only on a case-by-case basis.



    Let <vpn>, and <vpn's gateway> be the interface name of the VPN (generally tun0), and the IP address of the VPN's gateway, respectively. Then, the routes for any destinations passing through the VPN, more accurately its gateway <vpn's gateway>, have to be replaced by routes passing through <gateway>:



ip route del 0.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 0.0.0.0/1 via <gateway> dev <interface>

ip route del 128.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 128.0.0.0/1 via <gateway> dev <interface>


0.0.0.0/1 stands for IP addresses ranging from 0.0.0.1 to 127.255.255.255, and 128.0.0.0/1 from 128.0.0.1 to 255.255.254.



Voilà.






share|improve this answer

























  • Good solution path, via iproute2 instead of iptables. This is a great way to handle such situation. For the CIDR matcher suggestion, keep in mind that 0.0.0.0/1 and 128.0.0.0/1 match approx. half the internet, only parts of these ranges are reserved for specific purposes (e.g private networks).

    – hargut
    Jun 10 at 10:42











  • Thank you for this lightening. What do you mean when you say that it matches approximately half the internet? You want to say that: 1. the other half is for private-purpose, or rather, that 2. it lacks the half of all the IP addresses? (the 2. seems unlikely, I don't think there are IP addresses beyond 255.255.255.255, at any rate with IPv4).

    – Moth
    Jun 10 at 14:30











  • The calculation of the ranges in your answer is correct 0.0.0.0/1 from 0.0.0.1 to 127.255.255.255 and 128.0.0.0/1 from 128.0.0.1 to 255.255.255. But each of the the two selectors covers (approx.) half of the ipv4 based internet, and both contain private and public ip's in its range (e.g. 10.0.0.0/8, or 172.16.0.0/16, ...). So if you match either 0.0.0.0/1 or 128.0.0.0/1 for routing through vpn-gateway or gateway it seems not very reasonable, still it could be intended when wanting (approx.) half traffic through vpn-gateway and (approx.) the other half through gateway.

    – hargut
    Jun 10 at 14:54












  • Actually, in my answer both 0.0.0.0/1 and 128.0.0.0/1 are routed through <gateway> and not through <vpn's gateway>. But you are right, I think that <vpn's gateway> and <vpn address> don't have to be routed in the <gateway>, otherwise, the VPN would become unreachable. Am I right?

    – Moth
    Jun 10 at 20:40












  • Sorry, I've missed the fact that both are routed via the same gateway. In this case a single entry with 0.0.0.0/0 would be more clear.

    – hargut
    Jun 11 at 5:19













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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970661%2fmaking-a-server-behind-a-vpn-client-remain-reachable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Finally, to my problematic I found a solution inspired from:



https://lartc.org/howto/lartc.rpdb.multiple-links.html .



Here is how to proceed.



To configure the routing of the server so that it is attainable behind a VPN client, a separate routing table ought to be used to avoid an overlap of routing configurations of the two interfaces.



Let <interface>, <table>, <ip>, <gateway> and <network> be the interface name, the table, the IP address of <interface>, the gateway's IP address, and the IP address of the network (that provided by the ISP), respectively.



The procedure to follow is:



  1. Creation of the specific routing table of <interface>: creating the new table <table> in /etc/iproute2/rt_tables.



  2. Setting a different routing configuration for the interface associated to <gateway> by means of a specific table.



    The traffic towards <network> is associated to the interface <interface> and follows the specific routing table <table>:



    ip route add <network> dev <interface> src <ip> table <table>



    Building a default route via this gateway:



    ip route add default via <gateway> table <table>




  3. On <interface>, forcing the traffic from <ip> passing through <network>, to use the interface <interface>:



    ip route add <network> dev <interface> src <ip>



    The src argument is specified to make sure the right outgoing IP address is chosen.




  4. Associating the interface to the appropriate <network>:



    ip rule add from <ip> table



Key idea:



The key idea to understand, concerning why to use this technique here, is that for any request passing through the ISP node, here <network>, the latter will be an intermediate node of the response's route. This seems obvious, but forgetting it leads to not understand why <network> does matter in the routing configuration of the interface normally used to communicate with the server from outside.



Optional:




  1. Setting the routes for all destinations to pass through <gateway> instead of through the VPN's gateway. Useful when it is needed to use the VPN only on a case-by-case basis.



    Let <vpn>, and <vpn's gateway> be the interface name of the VPN (generally tun0), and the IP address of the VPN's gateway, respectively. Then, the routes for any destinations passing through the VPN, more accurately its gateway <vpn's gateway>, have to be replaced by routes passing through <gateway>:



ip route del 0.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 0.0.0.0/1 via <gateway> dev <interface>

ip route del 128.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 128.0.0.0/1 via <gateway> dev <interface>


0.0.0.0/1 stands for IP addresses ranging from 0.0.0.1 to 127.255.255.255, and 128.0.0.0/1 from 128.0.0.1 to 255.255.254.



Voilà.






share|improve this answer

























  • Good solution path, via iproute2 instead of iptables. This is a great way to handle such situation. For the CIDR matcher suggestion, keep in mind that 0.0.0.0/1 and 128.0.0.0/1 match approx. half the internet, only parts of these ranges are reserved for specific purposes (e.g private networks).

    – hargut
    Jun 10 at 10:42











  • Thank you for this lightening. What do you mean when you say that it matches approximately half the internet? You want to say that: 1. the other half is for private-purpose, or rather, that 2. it lacks the half of all the IP addresses? (the 2. seems unlikely, I don't think there are IP addresses beyond 255.255.255.255, at any rate with IPv4).

    – Moth
    Jun 10 at 14:30











  • The calculation of the ranges in your answer is correct 0.0.0.0/1 from 0.0.0.1 to 127.255.255.255 and 128.0.0.0/1 from 128.0.0.1 to 255.255.255. But each of the the two selectors covers (approx.) half of the ipv4 based internet, and both contain private and public ip's in its range (e.g. 10.0.0.0/8, or 172.16.0.0/16, ...). So if you match either 0.0.0.0/1 or 128.0.0.0/1 for routing through vpn-gateway or gateway it seems not very reasonable, still it could be intended when wanting (approx.) half traffic through vpn-gateway and (approx.) the other half through gateway.

    – hargut
    Jun 10 at 14:54












  • Actually, in my answer both 0.0.0.0/1 and 128.0.0.0/1 are routed through <gateway> and not through <vpn's gateway>. But you are right, I think that <vpn's gateway> and <vpn address> don't have to be routed in the <gateway>, otherwise, the VPN would become unreachable. Am I right?

    – Moth
    Jun 10 at 20:40












  • Sorry, I've missed the fact that both are routed via the same gateway. In this case a single entry with 0.0.0.0/0 would be more clear.

    – hargut
    Jun 11 at 5:19















2














Finally, to my problematic I found a solution inspired from:



https://lartc.org/howto/lartc.rpdb.multiple-links.html .



Here is how to proceed.



To configure the routing of the server so that it is attainable behind a VPN client, a separate routing table ought to be used to avoid an overlap of routing configurations of the two interfaces.



Let <interface>, <table>, <ip>, <gateway> and <network> be the interface name, the table, the IP address of <interface>, the gateway's IP address, and the IP address of the network (that provided by the ISP), respectively.



The procedure to follow is:



  1. Creation of the specific routing table of <interface>: creating the new table <table> in /etc/iproute2/rt_tables.



  2. Setting a different routing configuration for the interface associated to <gateway> by means of a specific table.



    The traffic towards <network> is associated to the interface <interface> and follows the specific routing table <table>:



    ip route add <network> dev <interface> src <ip> table <table>



    Building a default route via this gateway:



    ip route add default via <gateway> table <table>




  3. On <interface>, forcing the traffic from <ip> passing through <network>, to use the interface <interface>:



    ip route add <network> dev <interface> src <ip>



    The src argument is specified to make sure the right outgoing IP address is chosen.




  4. Associating the interface to the appropriate <network>:



    ip rule add from <ip> table



Key idea:



The key idea to understand, concerning why to use this technique here, is that for any request passing through the ISP node, here <network>, the latter will be an intermediate node of the response's route. This seems obvious, but forgetting it leads to not understand why <network> does matter in the routing configuration of the interface normally used to communicate with the server from outside.



Optional:




  1. Setting the routes for all destinations to pass through <gateway> instead of through the VPN's gateway. Useful when it is needed to use the VPN only on a case-by-case basis.



    Let <vpn>, and <vpn's gateway> be the interface name of the VPN (generally tun0), and the IP address of the VPN's gateway, respectively. Then, the routes for any destinations passing through the VPN, more accurately its gateway <vpn's gateway>, have to be replaced by routes passing through <gateway>:



ip route del 0.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 0.0.0.0/1 via <gateway> dev <interface>

ip route del 128.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 128.0.0.0/1 via <gateway> dev <interface>


0.0.0.0/1 stands for IP addresses ranging from 0.0.0.1 to 127.255.255.255, and 128.0.0.0/1 from 128.0.0.1 to 255.255.254.



Voilà.






share|improve this answer

























  • Good solution path, via iproute2 instead of iptables. This is a great way to handle such situation. For the CIDR matcher suggestion, keep in mind that 0.0.0.0/1 and 128.0.0.0/1 match approx. half the internet, only parts of these ranges are reserved for specific purposes (e.g private networks).

    – hargut
    Jun 10 at 10:42











  • Thank you for this lightening. What do you mean when you say that it matches approximately half the internet? You want to say that: 1. the other half is for private-purpose, or rather, that 2. it lacks the half of all the IP addresses? (the 2. seems unlikely, I don't think there are IP addresses beyond 255.255.255.255, at any rate with IPv4).

    – Moth
    Jun 10 at 14:30











  • The calculation of the ranges in your answer is correct 0.0.0.0/1 from 0.0.0.1 to 127.255.255.255 and 128.0.0.0/1 from 128.0.0.1 to 255.255.255. But each of the the two selectors covers (approx.) half of the ipv4 based internet, and both contain private and public ip's in its range (e.g. 10.0.0.0/8, or 172.16.0.0/16, ...). So if you match either 0.0.0.0/1 or 128.0.0.0/1 for routing through vpn-gateway or gateway it seems not very reasonable, still it could be intended when wanting (approx.) half traffic through vpn-gateway and (approx.) the other half through gateway.

    – hargut
    Jun 10 at 14:54












  • Actually, in my answer both 0.0.0.0/1 and 128.0.0.0/1 are routed through <gateway> and not through <vpn's gateway>. But you are right, I think that <vpn's gateway> and <vpn address> don't have to be routed in the <gateway>, otherwise, the VPN would become unreachable. Am I right?

    – Moth
    Jun 10 at 20:40












  • Sorry, I've missed the fact that both are routed via the same gateway. In this case a single entry with 0.0.0.0/0 would be more clear.

    – hargut
    Jun 11 at 5:19













2












2








2







Finally, to my problematic I found a solution inspired from:



https://lartc.org/howto/lartc.rpdb.multiple-links.html .



Here is how to proceed.



To configure the routing of the server so that it is attainable behind a VPN client, a separate routing table ought to be used to avoid an overlap of routing configurations of the two interfaces.



Let <interface>, <table>, <ip>, <gateway> and <network> be the interface name, the table, the IP address of <interface>, the gateway's IP address, and the IP address of the network (that provided by the ISP), respectively.



The procedure to follow is:



  1. Creation of the specific routing table of <interface>: creating the new table <table> in /etc/iproute2/rt_tables.



  2. Setting a different routing configuration for the interface associated to <gateway> by means of a specific table.



    The traffic towards <network> is associated to the interface <interface> and follows the specific routing table <table>:



    ip route add <network> dev <interface> src <ip> table <table>



    Building a default route via this gateway:



    ip route add default via <gateway> table <table>




  3. On <interface>, forcing the traffic from <ip> passing through <network>, to use the interface <interface>:



    ip route add <network> dev <interface> src <ip>



    The src argument is specified to make sure the right outgoing IP address is chosen.




  4. Associating the interface to the appropriate <network>:



    ip rule add from <ip> table



Key idea:



The key idea to understand, concerning why to use this technique here, is that for any request passing through the ISP node, here <network>, the latter will be an intermediate node of the response's route. This seems obvious, but forgetting it leads to not understand why <network> does matter in the routing configuration of the interface normally used to communicate with the server from outside.



Optional:




  1. Setting the routes for all destinations to pass through <gateway> instead of through the VPN's gateway. Useful when it is needed to use the VPN only on a case-by-case basis.



    Let <vpn>, and <vpn's gateway> be the interface name of the VPN (generally tun0), and the IP address of the VPN's gateway, respectively. Then, the routes for any destinations passing through the VPN, more accurately its gateway <vpn's gateway>, have to be replaced by routes passing through <gateway>:



ip route del 0.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 0.0.0.0/1 via <gateway> dev <interface>

ip route del 128.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 128.0.0.0/1 via <gateway> dev <interface>


0.0.0.0/1 stands for IP addresses ranging from 0.0.0.1 to 127.255.255.255, and 128.0.0.0/1 from 128.0.0.1 to 255.255.254.



Voilà.






share|improve this answer















Finally, to my problematic I found a solution inspired from:



https://lartc.org/howto/lartc.rpdb.multiple-links.html .



Here is how to proceed.



To configure the routing of the server so that it is attainable behind a VPN client, a separate routing table ought to be used to avoid an overlap of routing configurations of the two interfaces.



Let <interface>, <table>, <ip>, <gateway> and <network> be the interface name, the table, the IP address of <interface>, the gateway's IP address, and the IP address of the network (that provided by the ISP), respectively.



The procedure to follow is:



  1. Creation of the specific routing table of <interface>: creating the new table <table> in /etc/iproute2/rt_tables.



  2. Setting a different routing configuration for the interface associated to <gateway> by means of a specific table.



    The traffic towards <network> is associated to the interface <interface> and follows the specific routing table <table>:



    ip route add <network> dev <interface> src <ip> table <table>



    Building a default route via this gateway:



    ip route add default via <gateway> table <table>




  3. On <interface>, forcing the traffic from <ip> passing through <network>, to use the interface <interface>:



    ip route add <network> dev <interface> src <ip>



    The src argument is specified to make sure the right outgoing IP address is chosen.




  4. Associating the interface to the appropriate <network>:



    ip rule add from <ip> table



Key idea:



The key idea to understand, concerning why to use this technique here, is that for any request passing through the ISP node, here <network>, the latter will be an intermediate node of the response's route. This seems obvious, but forgetting it leads to not understand why <network> does matter in the routing configuration of the interface normally used to communicate with the server from outside.



Optional:




  1. Setting the routes for all destinations to pass through <gateway> instead of through the VPN's gateway. Useful when it is needed to use the VPN only on a case-by-case basis.



    Let <vpn>, and <vpn's gateway> be the interface name of the VPN (generally tun0), and the IP address of the VPN's gateway, respectively. Then, the routes for any destinations passing through the VPN, more accurately its gateway <vpn's gateway>, have to be replaced by routes passing through <gateway>:



ip route del 0.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 0.0.0.0/1 via <gateway> dev <interface>

ip route del 128.0.0.0/1 via <vpn's gateway> dev <vpn>
ip route add 128.0.0.0/1 via <gateway> dev <interface>


0.0.0.0/1 stands for IP addresses ranging from 0.0.0.1 to 127.255.255.255, and 128.0.0.0/1 from 128.0.0.1 to 255.255.254.



Voilà.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 11 at 10:41

























answered Jun 10 at 9:30









MothMoth

255 bronze badges




255 bronze badges












  • Good solution path, via iproute2 instead of iptables. This is a great way to handle such situation. For the CIDR matcher suggestion, keep in mind that 0.0.0.0/1 and 128.0.0.0/1 match approx. half the internet, only parts of these ranges are reserved for specific purposes (e.g private networks).

    – hargut
    Jun 10 at 10:42











  • Thank you for this lightening. What do you mean when you say that it matches approximately half the internet? You want to say that: 1. the other half is for private-purpose, or rather, that 2. it lacks the half of all the IP addresses? (the 2. seems unlikely, I don't think there are IP addresses beyond 255.255.255.255, at any rate with IPv4).

    – Moth
    Jun 10 at 14:30











  • The calculation of the ranges in your answer is correct 0.0.0.0/1 from 0.0.0.1 to 127.255.255.255 and 128.0.0.0/1 from 128.0.0.1 to 255.255.255. But each of the the two selectors covers (approx.) half of the ipv4 based internet, and both contain private and public ip's in its range (e.g. 10.0.0.0/8, or 172.16.0.0/16, ...). So if you match either 0.0.0.0/1 or 128.0.0.0/1 for routing through vpn-gateway or gateway it seems not very reasonable, still it could be intended when wanting (approx.) half traffic through vpn-gateway and (approx.) the other half through gateway.

    – hargut
    Jun 10 at 14:54












  • Actually, in my answer both 0.0.0.0/1 and 128.0.0.0/1 are routed through <gateway> and not through <vpn's gateway>. But you are right, I think that <vpn's gateway> and <vpn address> don't have to be routed in the <gateway>, otherwise, the VPN would become unreachable. Am I right?

    – Moth
    Jun 10 at 20:40












  • Sorry, I've missed the fact that both are routed via the same gateway. In this case a single entry with 0.0.0.0/0 would be more clear.

    – hargut
    Jun 11 at 5:19

















  • Good solution path, via iproute2 instead of iptables. This is a great way to handle such situation. For the CIDR matcher suggestion, keep in mind that 0.0.0.0/1 and 128.0.0.0/1 match approx. half the internet, only parts of these ranges are reserved for specific purposes (e.g private networks).

    – hargut
    Jun 10 at 10:42











  • Thank you for this lightening. What do you mean when you say that it matches approximately half the internet? You want to say that: 1. the other half is for private-purpose, or rather, that 2. it lacks the half of all the IP addresses? (the 2. seems unlikely, I don't think there are IP addresses beyond 255.255.255.255, at any rate with IPv4).

    – Moth
    Jun 10 at 14:30











  • The calculation of the ranges in your answer is correct 0.0.0.0/1 from 0.0.0.1 to 127.255.255.255 and 128.0.0.0/1 from 128.0.0.1 to 255.255.255. But each of the the two selectors covers (approx.) half of the ipv4 based internet, and both contain private and public ip's in its range (e.g. 10.0.0.0/8, or 172.16.0.0/16, ...). So if you match either 0.0.0.0/1 or 128.0.0.0/1 for routing through vpn-gateway or gateway it seems not very reasonable, still it could be intended when wanting (approx.) half traffic through vpn-gateway and (approx.) the other half through gateway.

    – hargut
    Jun 10 at 14:54












  • Actually, in my answer both 0.0.0.0/1 and 128.0.0.0/1 are routed through <gateway> and not through <vpn's gateway>. But you are right, I think that <vpn's gateway> and <vpn address> don't have to be routed in the <gateway>, otherwise, the VPN would become unreachable. Am I right?

    – Moth
    Jun 10 at 20:40












  • Sorry, I've missed the fact that both are routed via the same gateway. In this case a single entry with 0.0.0.0/0 would be more clear.

    – hargut
    Jun 11 at 5:19
















Good solution path, via iproute2 instead of iptables. This is a great way to handle such situation. For the CIDR matcher suggestion, keep in mind that 0.0.0.0/1 and 128.0.0.0/1 match approx. half the internet, only parts of these ranges are reserved for specific purposes (e.g private networks).

– hargut
Jun 10 at 10:42





Good solution path, via iproute2 instead of iptables. This is a great way to handle such situation. For the CIDR matcher suggestion, keep in mind that 0.0.0.0/1 and 128.0.0.0/1 match approx. half the internet, only parts of these ranges are reserved for specific purposes (e.g private networks).

– hargut
Jun 10 at 10:42













Thank you for this lightening. What do you mean when you say that it matches approximately half the internet? You want to say that: 1. the other half is for private-purpose, or rather, that 2. it lacks the half of all the IP addresses? (the 2. seems unlikely, I don't think there are IP addresses beyond 255.255.255.255, at any rate with IPv4).

– Moth
Jun 10 at 14:30





Thank you for this lightening. What do you mean when you say that it matches approximately half the internet? You want to say that: 1. the other half is for private-purpose, or rather, that 2. it lacks the half of all the IP addresses? (the 2. seems unlikely, I don't think there are IP addresses beyond 255.255.255.255, at any rate with IPv4).

– Moth
Jun 10 at 14:30













The calculation of the ranges in your answer is correct 0.0.0.0/1 from 0.0.0.1 to 127.255.255.255 and 128.0.0.0/1 from 128.0.0.1 to 255.255.255. But each of the the two selectors covers (approx.) half of the ipv4 based internet, and both contain private and public ip's in its range (e.g. 10.0.0.0/8, or 172.16.0.0/16, ...). So if you match either 0.0.0.0/1 or 128.0.0.0/1 for routing through vpn-gateway or gateway it seems not very reasonable, still it could be intended when wanting (approx.) half traffic through vpn-gateway and (approx.) the other half through gateway.

– hargut
Jun 10 at 14:54






The calculation of the ranges in your answer is correct 0.0.0.0/1 from 0.0.0.1 to 127.255.255.255 and 128.0.0.0/1 from 128.0.0.1 to 255.255.255. But each of the the two selectors covers (approx.) half of the ipv4 based internet, and both contain private and public ip's in its range (e.g. 10.0.0.0/8, or 172.16.0.0/16, ...). So if you match either 0.0.0.0/1 or 128.0.0.0/1 for routing through vpn-gateway or gateway it seems not very reasonable, still it could be intended when wanting (approx.) half traffic through vpn-gateway and (approx.) the other half through gateway.

– hargut
Jun 10 at 14:54














Actually, in my answer both 0.0.0.0/1 and 128.0.0.0/1 are routed through <gateway> and not through <vpn's gateway>. But you are right, I think that <vpn's gateway> and <vpn address> don't have to be routed in the <gateway>, otherwise, the VPN would become unreachable. Am I right?

– Moth
Jun 10 at 20:40






Actually, in my answer both 0.0.0.0/1 and 128.0.0.0/1 are routed through <gateway> and not through <vpn's gateway>. But you are right, I think that <vpn's gateway> and <vpn address> don't have to be routed in the <gateway>, otherwise, the VPN would become unreachable. Am I right?

– Moth
Jun 10 at 20:40














Sorry, I've missed the fact that both are routed via the same gateway. In this case a single entry with 0.0.0.0/0 would be more clear.

– hargut
Jun 11 at 5:19





Sorry, I've missed the fact that both are routed via the same gateway. In this case a single entry with 0.0.0.0/0 would be more clear.

– hargut
Jun 11 at 5:19

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970661%2fmaking-a-server-behind-a-vpn-client-remain-reachable%23new-answer', 'question_page');

);

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







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020