开发者

Changing a domains IP address with PHP

I currently have an Ubuntu server running Bind. I have a subdoamin (home.example.com) linking to my home ip address. I was wanting to be able to use a php script that, when visited and authenticated would change the ip address of the subdomain. I was thinking I could use php to edit the bind config files,开发者_如何学Python then run the command "service bind restart". Would this be the best way to do it?


I agree 'nsupdate' would be a better solution, but it wont need PHP, at least not to restart the server. I think it's very bad if your webserver could do so.

In OS-X (and I guess in Linux there's a an equivalent - or else the crontab) the files /etc/ppp/ip-up.sh and /etc/ppp/ip-down.sh are executed once you IP changes (but appeareantly not on WiFi - so for that I use a crontab).

touch /etc/ppp/ip-up.sh ln -s !$ /etc/ppp/ip-down.sh

/etc/ppp/ip-up.sh:

#!/bin/bash
H=domain.mobi
IP=`curl -s http://domain.mobi/ip.php` # or wget, etc.

nsupdate -v -y tsig.$H:Wwr82TQdx3biQdx3biq2Pibi7IMq2PGxETCetcETC== > /dev/null << EOF
server 129.8.7.53
zone $H
update delete john.$H SPF
update delete john.$H TXT
update add    john.$H 600 SPF "v=spf1 ip4:$IP -all"
update add    john.$H 600 TXT "v=spf1 ip4:$IP -all"
send
EOF

Now if your master does notify/axfr/ixfr then in no-time your zone is updated. The ip.php in above script is just a simple:

<?php
header("Content-Type: text/plain");
echo $_SERVER['REMOTE_ADDR'];
?>

These are examples of people who are doing basicly the same thing:

  • http://www.chrisk.de/blog/2011/02/how-to-create-your-own-dyndns-service/
  • http://caunter.ca/nsupdate.txt


You should look into RFC 2136. The 'nsupdate' command implements that, but that requires your PHP script to run a command on the server. A search for "RFC 2136" turns up https://pear.php.net/manual/en/package.networking.net-dns.net-dns-updates-example.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜