3

The OpenVPN server gives an internal IP addresses to each client that is connecting outside of the network. I want to store these IP addresses in a database after they are assigned. Is there an easy way to tell which IP addresses were handed out by the OpenVPN Server?

thanks for Help

3
  • Have you looked at the logs of the OpenVPN server? It should just be a simple matter of greping for a successful log in line and piping that to your database utility. Jun 27, 2019 at 3:12
  • You can predefine an IP address for each client using entries in the ccd directory. Jun 27, 2019 at 16:10
  • the address are dynamically assigned
    – taybinakh
    Jun 27, 2019 at 21:23

2 Answers 2

2

If these aren't statically assigned there isn't a good way to do this other than to extract them from the logfiles since the connections will be randomly assigned IP addresses.

If they are statically assigned AND you are using the Open VPN AccessServer you can do it this way:

sudo /usr/local/openvpn_as/scripts/sacli UserPropGet

which should yield a list of the IP addresses in the output which should look something like this:

{
  "<< name_of_user_profile >>": {
    ...
    "conn_ip": "xxx.xxx.xxx.xxx",
    ...
  },
  ...
}

where the conn_ip is the connection IP address.


If you are trying to merely log users IP addresses and deposit that info into a DB then you might look at this:

Where are the OpenVPN connection logs and configuration files?

In that case you are using an OpenVPN Access Server you may want to try:

grep "primary virtual IP" /var/log/openvpnas.log** > output_file_name

which will give you a file with all of the IP addresses associated with all the users. From there you can further modify the output to get just the bits you want from the file.

5
  • Thanks, yes he address are dynamically assigned i will try that, my goal is to applicate for each user a rule to connect for just some device, for example ,this user X can connect just to device X. also i must first know for each user that he have, and store it in Database.
    – taybinakh
    Jun 27, 2019 at 21:16
  • I've modified the answer to get you more/less exactly what you're looking for in your case--it should work on virtually any OpenVPN server--not just the professional one (with a few modifications, like your log names may be a little different.) If that's good enough you can mark it as 'answered'.
    – Penguino
    Jun 27, 2019 at 22:16
  • thanks , i will try it, my senrio is when clients are connected get IP and when they are disconnected get IP of disconnected , also for any change ==> update DB i want to use Option --client connect /path/script_parsing_connected_IP.sh -- client disconnecz /path/script_parsing_disconnected_IP.sh when i try it, i will tell you if work
    – taybinakh
    Jun 29, 2019 at 22:14
  • 1
    hi, i tried what you tell me , its work. i write also a script client-connect and can know adress IP with variable env. common_name and ip_config_pool ans its work... know i will develop my scipt , to know in runtime (receive notification) when a client connect or disconnect and store in DB
    – taybinakh
    Jul 4, 2019 at 14:49
  • cat /var/log/openvpnas.log | grep "primary virtual IP" worked perfectly for me 👍 Feb 23, 2023 at 18:34
1

You should have a look at /etc/openvpn/openvpn-status.log:

OpenVPN CLIENT LIST
Updated,Fri Sep  4 11:07:18 2020
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
client1,11.12.13.14:44444,50000,25000,Fri Sep  4 11:00:54 2020
client2,11.12.13.15:44444,27000,5500,Fri Sep  4 11:00:52 2020
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
10.8.0.7,client1,11.12.13.14:44444,Fri Sep  4 11:06:13 2020
10.8.0.6,client2,client2,11.12.13.15:44444,Fri Sep  4 11:03:56 2020
GLOBAL STATS
Max bcast/mcast queue length,2
END
1
  • 1
    I used openvpn-hook "--client-connect" and "--learn-address". Via comon name, virtual address , when the user connect openvp the script return these values
    – taybinakh
    Sep 4, 2020 at 9:24

You must log in to answer this question.

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