P
P
pashaxp2013-04-25 17:56:33
SSH
pashaxp, 2013-04-25 17:56:33

Find out the white IP address of the router from the server behind the NAT?

Greetings!

There is a small problem, I hope the all-knowing Habr will help to solve it.

So, there is an ADSL router that receives 1 white IP address (dynamic) from the provider. Next, we have a server with FreeBSD, which is behind a NAT with a gray IP address (static). The router is configured with dynamic dns (dyndns.org). Periodically, the router reconnects to the provider, and the IP address changes, but the dyndns service is not updated, because (I believe) the router and the dyndns service on it are arranged in such a way that the information will be synchronized only 1 time per 1 router boot. Roughly speaking, in order for the modem's IP address to be updated on the NS dyndns servers, the router must be rebooted. This option is not acceptable.

What interests you: you need to know at any given time which white IP is being used. Is it possible to somehow send the router's white IP via cron to your mailbox from a server with a gray IP, for example, using a script from the ssh console? If possible, then you are also interested in how exactly you can get this white IP? Can I execute a php script, somehow "grab" the IP, and then send it to email or using php-mail, or from the ssh console using sendmail?

In general, I will be glad to any proposed solutions!
P.S. If you need any more information, I will provide :)

Answer the question

In order to leave comments, you need to log in

6 answer(s)
F
FilimoniC, 2013-04-25
@FilimoniC

Put DynDns on the server. So you'll at least know what's going on

X
XogN, 2013-04-25
@XogN

You can find out the ip address from the console, for example, with the wget -O - -q icanhazip.com command

X
xaker1, 2013-04-25
@xaker1

You can take ip from ifconfig.me/ip , the same curl`om - and there already do what you want, you can immediately report a new ip to dyndns via api.

M
mastini, 2013-04-25
@mastini

Why not update dyndns from the server using cron?

0
074909, 2013-04-27
@074909

1. Take the external address from the router via SNMP, if the router supports it;
2. pick up from the console of the router, if it can be a telnet server;
3. get the status page from the web muzzle of the router with curl or wget and parse the external address.

L
lmaxximl, 2013-04-29
@lmaxximl

everything is simple, I have a modem on the bridge and a script in the crown every 10 minutes:

#!/bin/sh
#Скрипт отправляет на почту текущий динамический адрес

#Переменные
LAST_IP=`cat /root/last_ip`
INTERFACE="dsl1"
STRING=`ifconfig $INTERFACE | grep "inet addr"`
IP=`echo $STRING | gawk -F: '{print $2}' | gawk -F' ' '{print $1}'`;

#Узнаем IP и заносим его в файл /root/last_ip если ip совпадаеи с ip что в файле то он не перезаписываеться
if [ "$LAST_IP" != "$IP" ]; then

#Если отличаеться то записываеться
echo $IP > /root/last_ip

#Отправляем содержимое на email 
cat | grep "" /root/last_ip | ssmtp -v -s 'ADSL' [email protected]

fi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question