4

I'm trying for several days now to solve my problem. I have been using openvpn for windows for quite a while and after replacing windows with ubuntu 13.10, I was happy to see that openvpn is available for ubuntu as well.

I copied my settings from windows and in /var/log/syslog I see that my connection is successfully created. However, no matter what I do, I'm unable to set routes. In windows, this was simply done by script that worked as follows (ip addresses slightly differ since I have to keep them private):

c:\windows\system32\route.exe delete 55.78.16.20
c:\windows\system32\route.exe delete 55.78.16.0
del tmp.cmd
c:\windows\system32\route.exe print | grep.exe -m1 "^ *0.0.0.0" | sed.exe s/\x20\x20*/\t/g | cut.exe -f4 | sed "s/.*/c:\\windows\\system32\\route.exe add 55.78.16.20 mask 255.255.255.255 &/" > tmp.cmd
c:\windows\system32\route.exe print | grep "^ *172.16.0.1" | sed s/\x20\x20*/\t/g | cut -f4 | sed "s/.*/c:\\windows\\system32\\route.exe add 55.78.16.0 mask 255.255.255.0 &/" >> tmp.cmd
tmp.cmd

After connection was set and above script was executed, connections to my servers went through VPN, while all other went normally.

Since this script uses grep, sed and cut, I figured I can easily "translate" it to linux. And I did it, except for the fact that I'm a bit unsure how to use route command to set my connection properly.

P.S. I also tried setting VPN using network manager, but the same question appears: how to add routes?

Thx in advance

2 Answers 2

15

On OpenVPN you can accomplish this in three ways:

  1. Server pushes the route to ALL the clients. You do this by putting the route command in the server.conf file, on the server
  2. Server pushes the route to a single client. You do this by putting the route command in a client-specific file in what's known as the client-config folder on the server
  3. Client sets up the route. You do this by putting the route into your client config (ovpn on windows) file

In all three cases it looks like this:

route [routeaddress] [netmask]

i.e.

route 172.92.3.0 255.255.0.0

Consult this page for details.

http://openvpn.net/index.php/open-source/documentation/howto.html

1
  • 2
    This is the right answer. It should be selected as such. Jan 31, 2017 at 16:18
0

First and foremost:

You have been using GNU tools on windows? Like WTH man.

Second:

Basically you have two ways to achieve the same thing.

The first is to use the ip command. You would do something like ip route add .... though I'm kinda oldschool and dislike ip so I'm not too sure about how would you do that but man ip will certainly help you there.

The second is to use the older route command. With this you can modify the kernel's routing table. Issuing man route will pretty much tell you what you need to do, but for the sake of completeness it should be something like route add <target IP you want to reach> <interface that you want the target to be reached>. You can set the target IP to entire subnets, but then you will have to add in a gateway for that too. (And set up a route to that gateway.)
Oh and you can check your interfaces with both ip and ifconfig.

Let me know how it works out for you.

2
  • actually, ifconfig did the job - told me what should i select as gateway for that particular address i was wondering about. thx.
    – playcat
    Jan 18, 2014 at 0:22
  • What is WTH? google.com/search?q=gnu+wth Jan 31, 2017 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .