If you need to use DDNS, there are too many fake of free DDNS services on the Internet.
I have been cheated several times, but this is the one I have used. It is really free and easy to setup. You can take a look .
https://www.duckdns.org/
DDNS is also called dynamic DNS, which allows Our dynamic IP gets a domain name.
In this way, we can access our dynamic public IP through the domain name.
For example, my ISP is Hi-Net, and the home type is only willing to give one static IP and six dynamic IPs. Does that mean that it is impossible to use dynamic IPs to set up a website?
Of course, As long as you have DDNS, you can get it done, and if you have your own domain name, but the certificate provider does not provide an API for you to dynamically update the DNS record,
you can also point your domain name to the DDNS domain name through the CNAME setting, In this way, you can still use your own domain name to connect to the host with dynamic IP🥰.
The diagram is as follows:
host -t a bbb.e-course.app
bbb.e-course.app is an alias for imacbbb.duckdns.org.
imacbbb.duckdns.org has address 111.248.139.21
Here I provide a dynamically updated bash for reference, please note that you need to adjust the content of bash to match your own environment according to the actual situation.
I just provide a concept and method here. You can have two bashes, one to check whether the IP has changed, and the other to update the IP.
check_ip_changed.sh
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
DNS_IP=$(host -t a bbb.e-course.app 8.8.8.8|grep address|awk '{print $4}')
echo ${DNS_IP}
IP=`ifconfig eth0|grep 'inet'|awk '{print $2}'`
echo ${IP}
if [ $DNS_IP != $IP ]; then
echo "Update DDNS"
/root/ddns.sh
fi
Explanation:
first. You need to adjust the command according to the actual situation to obtain the DNS IP resolved by your own current DNS. For example, I obtained it through DNS
Second, you need to be able to use commands to obtain the IP of your external network card, my example The middle network card is eth0, your network card should be ppp0, I changed the name of this network card.
Three, It can be seen that in the above bash, the DNS_IP and IP will be compared, and if they are different, ddns.sh will be executed to update the IP of dynamic DNS.
The content of ddns.sh is below, you need to adjust the correct subdomain, token and network card
#!/bin/bash
SUBDOMAIN=<SUBDOMAIN>
TOKEN=<YOUR TOKEN>
IP=`ifconfig eth0|grep 'inet'|awk '{print $2}'`
echo "update ${SUBDOMAIN}.duckdns.org => IP:${IP}"
curl "https://www.duckdns.org/update/${SUBDOMAIN}/${TOKEN}/${IP}"
4. After confirming that there is no problem, put it into the schedule and check it every minute.
* * * * * /root/check_ip_changed.sh
PPPoE may be disconnected by ISP, you can refer to my other article
BASH for my redial pppoe
No Comment
Post your comment