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
32 Answers
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.
4You 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