# remote machine helper (kind of like no-ip)



## mrhobbeys (Oct 4, 2012)

I have a FreeBSD server setup on a business internet connection with a static IP address. I was wondering if it is possible to have my home PC connect to this server and maybe report its IP or somehow let me connect through this static IP. The goal is to eliminate steps from when there is a problem. 

My current setup is to use the port forwarding on the router to the internal IP of the machine I want to connect to, but if my internal network changes for some reason I have to change all the settings. At other times the IP of the "whole" network changes from the ISP. In either case I use teamviewer to login and make any corrections I need, both time consuming and annoying.


----------



## SirDice (Oct 4, 2012)

A lot of "home" routers support DynDNS nowadays. That would at least take care of the ISP side.

Your internal network shouldn't change that much, I have been using the same addresses for the past decade or so. And I have added/removed quite a lot from it in the mean time.


----------



## Mr_P (Oct 4, 2012)

I agree with SirDice. In case your router doesn't have DynDNS (or you don't want a site to monitor your home router) and there is a real weird problem in your internal network ip assignment (???) you can monitor your external ip by yourself. Write a script based on wget command:
1) wget http://www.whatismyip.com/ | vi myip //or whatever other text editor you want, or filename
2) grep (options) myip //to collect your external ip shown in the page
3) check if this i.p is the same with your old one //stored somewhere
4) if your new i.p is not the same => sendmail (a mail of yours)

By that you don't need any DynDNS or other special configuration. Hope you don't think I am crazy xD


----------



## mrhobbeys (Oct 4, 2012)

I looked into both no-ip and dnydns, but I was hoping to make some sort of free option.

As for the network addresses changing internally it only happens once in awhile but is extremely annoying when it does happen. I have tried to figure out why it does this and was never able to pinpoint a cause mostly because it happens so seldom.


----------



## mrhobbeys (Oct 4, 2012)

I also think when I try to search this on google I must be way off from what I type to what I actually want.


----------



## mrhobbeys (Oct 5, 2012)

Mr_P said:
			
		

> I agree with SirDice. In case your router doesn't have DynDNS (or you don't want a site to monitor your home router) and there is a real weird problem in your internal network ip assignment (???) you can monitor your external ip by yourself. Write a script based on wget command:
> 1) wget http://www.whatismyip.com/ | vi myip //or whatever other text editor you want, or filename
> 2) grep (options) myip //to collect your external ip shown in the page
> 3) check if this i.p is the same with your old one //stored somewhere
> ...



We must have posted at the same time or something I missed this one. I will give this a try and will post back what ever I come up with.


----------



## mrhobbeys (Oct 18, 2012)

I have found a solution I think I am still testing it. So far this is what I have and I was trying to get it to work on a debian machine but seem to be missing some dependencies. Now I am trying it on my FreeBSD server so I will give updates as soon as I figure out what actually works.


```
#!/bin/bash

IPFILE=/etc/ipaddress

CURRENT_IP=$(wget -q -O - http://www.whatismyip.com/automation/n09230945.asp)

MAIL_FROM="From: noreply@domain.org"

if [ -f $IPFILE ]; then
KNOWN_IP=$(cat $IPFILE)
else
KNOWN_IP=
fi

if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
echo $CURRENT_IP > $IPFILE

MAIL_SUBJECT="IP address for unit 1 has changed"
MAIL_BODY="The IP address for unit 1 has been changed to $CURRENT_IP. Please change the nameserver records accordingly."

echo $MAIL_BODY | mail -a "$MAIL_FROM" -s "$MAIL_SUBJECT" -c myemail@provider.com mybackupemail@provider.com
logger -t ipcheck -- IP changed to $CURRENT_IP
else
logger -t ipcheck -- cdNo IP change
fi
```

I found it on an Ubuntu based forum, my debian system seems not to have the right mail package installed. I am adjusting it for one I have substituted (mailutils) but I am about to try this on my FreeBSD as is in the next 20min or so. (update coming)


----------



## mrhobbeys (Oct 18, 2012)

It seems I have many changes to make at this point...

I will post back as I make progress for my FreeBSD system although I must work on my debian system first as I need it the most.


----------



## mrhobbeys (Nov 1, 2012)

I have changed direction on how to do this instead of using the mail function I am using this simple FTP script:

```
HOST=ftp.site.site
USER=username
PASS=password
ftp -inv $HOST << EOF

user $USER $PASS
cd /ftpsite/ipplace
put yourip.txt

bye
```

I have tried editing my original script I found I came up with this

```
## Get IP of machine encrypt it to send to FTP server
## Make changes to all of the variables to match your settings (FTP part not included yet still trouble shooting)
## Make your Key before hand and store it on your computer for decryption
## Set Cron to make it run however often you would like


# To make Key
# openssl genrsa -out key.txt 2048
IPFILE=/home/user/special/ipaddress

CURRENT_IP=$(wget -q -O - http://automation.whatismyip.com/n09230945.asp)

if [ -f $IPFILE ]; then
KNOWN_IP=$(cat $IPFILE)
else
KNOWN_IP=
fi

if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
echo $CURRENT_IP > $IPFILE

echo $IPFILE | openssl rsautl -inkey key.txt encrypt >/home/user/special/yourip.txt


logger -t ipcheck -- IP changed to $CURRENT_IP
else
logger -t ipcheck -- No IP change
fi
```

So far running this does not populate the "yourip.txt" file, but it will create the file at 0byte. I really have no clue what I have done wrong here. Also this does get the IP and populate the "ipaddress" file.

***EDIT
I just found the problem so on to the next part. To get this to work fix the openssl line to this:

```
openssl rsautl -in /home/user/special/ipaddress -inkey key.txt -encrypt >/home/user/special/yourip.txt
```

***EDIT 2
Works Post questions. I had a problem with the host I was using but after figuring out how it wanted the ftp passed I was all good.

```
## Get IP of machine and send it encrypted to FTP server
## Make changes to all of the variables to match your settings
## Make your Key before hand and store it on your computer for decryption
## Set Cron to make it run however often you would like


# To make Key
# openssl genrsa -out key.txt 2048

IPFILE=/home/user/special/ipaddress

CURRENT_IP=$(wget -q -O - http://automation.whatismyip.com/n09230945.asp)

HOST=ftp.site.site
USER=username
PASS=password

updip()
{
ftp -inv $HOST << EOF
user $USER $PASS 
cd /path/morepath # this may not be needed and you also need to remove this commit as the script will pass it to the FTP
put /home/user/special/yourip.txt /path/morepath/yourip.txt
bye
EOF
}

if [ -f $IPFILE ]; then
KNOWN_IP=$(cat $IPFILE)
else
KNOWN_IP=
fi

if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
echo $CURRENT_IP > $IPFILE

openssl rsautl -in /home/user/special/ipaddress -inkey key.txt -encrypt >/home/user/special/yourip.txt | updip

logger -t ipcheck -- IP changed to $CURRENT_IP
else
logger -t ipcheck -- No IP change
fi
```


----------



## chatwizrd (Nov 1, 2012)

or just install dns/noip


----------



## mrhobbeys (Nov 3, 2012)

My goal was something free. So I am I missing something about your solution?


----------

