Voọc 1 chút, kết hợp giữa cả cái phương án 1 và 2 của bác chủ (mò thôi bác này rành chỉ giáo thêm nhé)
![Big grin :D :D](https://data.voz.vn/styles/next/xenforo/smilies/popo/biggrin.png?v=01)
1. ssh tới VPS, sudo su các bước chuẩn bị..
#Đầu tiên thì tương tự
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --zone=public --add-port=53/udp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --zone=public --add-port=853/tcp --permanent
#Tạo
whitelist
firewall-cmd --new-ipset=
whitelist --type=hash:net --option=family=inet --option=hashsize=4096 --option=maxelem=200000 --permanent
#Tạo sh để lấy ip từ DDNS của mình add vào
whitelist trên (có thể sáng tạo thêm = nhiều file sh khác nhau cho mỗi DDNS)
nano myip.sh
#Edit code phần YOUR-DDNS rồi paster vào editer, Crtl + X -> y
Code:
#/bin/sh
date
#check if file already there if not, create it
if [ -r /run/myip ]
then
echo "file there"
else
echo "file not there"
dig +short i.home.mollberg.de > /run/myip
firewall-cmd --ipset=whitelist --permanent --add-entry="$myipnew"
fi
#get old IP
myipold=$(</run/myip)
echo "$myipold"
#get new IP
myipnew=$(dig +short YOUR-DDNS-NAME)
echo "$myipnew"
#compare new and old ip, do nothing if nothing changes, remove old ip and allow new IP if IP has changed
if [ "$myipold" = "$myipnew" ]
then
echo "same IP"
else
echo "diff IP"
firewall-cmd --ipset=whitelist --permanent --remove-entry="$myipold"
firewall-cmd --ipset=whitelist --permanent --add-entry="$myipnew"
firewall-cmd --reload
dig +short YOUR-DDNS-NAME > /run/myip
fi
#Test thử
./myip.sh
#Sau đó:
firewall-cmd --zone=
public --add-source=ipset:
whitelist --permanent
firewall-cmd --set-default-zone=drop
firewall-cmd --reload
#Nếu thành công thì chạy cron để cứ 1 tiếng nó check IP DDNS 1 lần nhé
EDITOR=nano crontab -e
add thêm dòng
0 * * * 0 root /home/opc/myip.sh >> /var/log/myip.log