1

How to start VPN on Ubuntu server (in order to change server IP address) that is remotely controlled by VNC-viewer?

I use Expressvpn and this guide: https://www.expressvpn.com/support/vpn-setup/linux-openvpn-terminal/ to set VPN on Ubuntu 14.04.3 LTS. When I try to connect to desired location (step 5 in guide) I am being logged out from VNC-viewer. I believe that IP address was changed, however now I have to reconnect to my server by entering new IP address to VNC-viewer. I do not know newly generated IP address, since VPN IP addresses are different every time I start VPN. The Expressvpn support team do not know how to solve this problem. Trying to solve this problem by my self took me days with no working solution. I would be very grateful for any help.

6
  • 1
    So are you connecting to a remote computer using VNC-viewer, and starting a VPN client on that remote computer to connect to a different remote computer, and when you do that, your VNC-viewer session ends? It is not clear to me what your use case is. Jan 23, 2016 at 3:38
  • I am connecting to a remote computer using VNC-viewer, and starting a VPN client on that remote computer in order to change IP address of that remote computer.
    – Fataho
    Jan 23, 2016 at 3:44
  • When I attempt to start VPN (I believe IP is changed at that moment), VNC-viewer session ends and I cannot connect to server.
    – Fataho
    Jan 23, 2016 at 3:50
  • OK, I attempted to reproduce this problem. I connected from a 64 bit 14.04 system to a 32 bit 12.04 system using VNC over remmina. I then started a VPN client on the 12.04 machine and connected to a VPN. I did not lose the VNC connection. So what you wish to do seems to be possible. But there are many variables. Can you install remmina and try with that, in case the problem is VNC-viewer? Jan 23, 2016 at 4:08
  • I've tryed this, and it is reproducable. The ubuntu server will reject any incoming traffic when connectted to VPN. I don't think this is because ip address is changed. It is because all you network traffic is using the VPN network(tun1 for ex.), so the network you use(eth0 for ex.) for vnc viewer or anything else will not working after connected to the VPN server. I think it is possible to let the vpn to route the network(eth0) you use for vnc viewer but it should be configured in the VPN server side. You should check this article: secure-computing.net/wiki/index.php/OpenVPN/Routing
    – realhu
    Jan 23, 2016 at 4:32

1 Answer 1

0

I solved this problem by creating a python script to check my external ip on the Linux box every and gmail it to me if it's different. I used cron to run it every 3 mins. It's really clunky but it works great.

#! /usr/bin/env python


# Check for internet connection

import urllib2
import time
import string

def internet_on():
    try:
        response=urllib2.urlopen('http://www.google.com/',timeout=1)
        return True
    except urllib2.URLError as err: pass
    return False

#loop_value = 1
#while (loop_value == 1):
#    try:
#   urllib2.urlopen("http://www.google.com")
#    except urllib2.URLError, e:
#   time.sleep( 10 )
#    else:
#   loop_value = 0

# Commands to be run if internet connection is present:
if internet_on():
    # Get external IP from canyouseeme.org by searching html page for an IP address
    import urllib
    import re 
    f = urllib.urlopen("http://myip.dnsdynamic.org/")
    html_doc = f.read()
    f.close()
    m = re.search('(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',html_doc)
    # print html_doc
    #print m.group(0)
    current_ipaddress = m.group(0)

    # Look at last line of ip log file
    IPlog = open ('iplog.txt')
    lineList = IPlog.readlines()
    IPlog.close()
    # print (lineList)
    # print ("The last line is:")
    # print (lineList[len(lineList)-1])
    # or simply
    # print (lineList[-1])
    # print current_ipaddress

    # See if current IP has changed from last logged
    if current_ipaddress + "\n" <> lineList[-1]:
        #Append ip address to ip log file
        f = open('iplog.txt','a')
        localtime = time.asctime( time.localtime(time.time()) )
        f.write(localtime + "\n" + current_ipaddress + "\n")
        # python will convert \n to os.linesep
        f.close()

        # Mail new ip    
        import smtplib
        smtp_server = 'smtp.gmail.com'
        smtp_port = 587
        sender = '****@gmail.com'
        # recipients = ["*****[email protected]", "john@***.com"]
        recipients = ["*****@***.com"]


        subject = 'SERVER ALERT'
        body = 'Server IP address has changed to: ' + current_ipaddress
        password = '**********************'
        smstext = body 
        body = "" + body + ""

        headers = ["From: " + sender,
               "Subject: " + subject,
               #"To: " + "Fred and John",
               "To: " + "John",
               "MIME-Version: 1.0",
               "Content-Type: text/html"]
        headers = "\r\n".join(headers)

        session = smtplib.SMTP(smtp_server, smtp_port)

        session.ehlo()
        session.starttls()
        session.ehlo
        session.login(sender, password)

        session.sendmail(sender, recipients, headers + "\r\n\r\n" + body)
        session.quit()


        # Google Voice SMS send
        import pygvoicelib
        conn = pygvoicelib

        username="**************"
        apppass="****************************"
        auth_token="***********************************"
        client = conn.GoogleVoice(username,apppass,auth_token,rnr_se)
        #phone number below
        client.sms('1212*******',smstext)

You must log in to answer this question.

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