{"id":144,"date":"2022-12-01T20:02:02","date_gmt":"2022-12-01T12:02:02","guid":{"rendered":"https:\/\/namo.one\/?p=144"},"modified":"2022-12-01T20:05:43","modified_gmt":"2022-12-01T12:05:43","slug":"%e8%87%aa%e5%8a%a8%e7%94%a8%e8%8e%b7%e5%8f%96%e5%88%b0%e7%9a%84ddns-ip%e5%9c%b0%e5%9d%80%e5%8e%bb%e6%9b%b4%e6%96%b0iptable%e8%a7%84%e5%88%99%e7%9a%84%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/byso.top\/?p=144","title":{"rendered":"\u81ea\u52a8\u7528\u83b7\u53d6\u5230\u7684ddns ip\u5730\u5740\u53bb\u66f4\u65b0iptable\u89c4\u5219\u7684\u811a\u672c"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5148\u81ea\u52a8\u66f4\u65b0cloudflare\u7684dns\u8bb0\u5f55<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u800c\u540e\u5c06\u5bf9\u5e94\u7684dns\u5730\u5740\u66f4\u65b0\u4ee5\u4e0b\u811a\u672c\u7684HOSTNAME<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/root\/ddns2iptables.sh<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n#allow a ddns name to iptables rule\n\nHOSTNAME=hostname\nLOGFILE=\/home\/ip.log\n\nCurrent_IP=$(host $HOSTNAME | cut -f4 -d' ')\n\nif &#91; $LOGFILE = \"\" ] ; then\n  iptables -I INPUT 9 -s $Current_IP -j ACCEPT\n  echo $Current_IP &gt; $LOGFILE\nelse\n\n  Old_IP=$(cat $LOGFILE)\n\n  if &#91; \"$Current_IP\" = \"$Old_IP\" ] ; then\n    echo IP address has not changed\n  else\n    iptables -D INPUT -s $Old_IP -j ACCEPT\n    iptables -I INPUT 9 -s $Current_IP -j ACCEPT\n    iptables-save &gt; \/etc\/iptables.conf\n    echo $Current_IP &gt; $LOGFILE\n    echo iptables have been updated\n  fi\nfi\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b8c\u6210\u4ee5\u540e\uff0ciptables\u5373\u53ef\u5c06\u81ea\u5df1\u7684\u516c\u7f51\u5730\u5740\u6dfb\u52a0\u5230\u73b0\u6709\u89c4\u5219\uff0c\u4f7f\u5f97\u672c\u5730\u6ca1\u6709\u56fa\u5b9a\u516c\u7f51\u5730\u5740\u7684\u8bbe\u5907\u53ef\u4ee5\u8fdc\u7a0b\u83b7\u5f97\u8fde\u63a5\u7684\u7aef\u53e3\u5f00\u653e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u589e\u52a0\u4e00\u6761crontab\u7684\u6267\u884c\u547d\u4ee4\uff0c\u4f7f\u5f97\u5176\u53ef\u4ee5\u6bcf5\u5206\u949f\u81ea\u52a8\u6267\u884c\u4e00\u4e0b\uff0c\u786e\u4fdd\u6700\u65b0\u7684\u52a8\u6001ip\u5730\u5740\u88ab\u767b\u8bb0\u5728\u6848<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/5 * * * * root \/root\/ddns2iptables.sh > \/dev\/null 2>&amp;1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u81ea\u52a8\u66f4\u65b0cloudflare\u7684dns\u8bb0\u5f55 \u800c\u540e\u5c06\u5bf9\u5e94\u7684dns\u5730\u5740\u66f4\u65b0\u4ee5\u4e0b\u811a\u672c\u7684HOSTNAME \u5b8c\u6210\u4ee5\u540e\uff0ci [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,2,3],"tags":[],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-iptables","category-linux-applications","category-vps"],"_links":{"self":[{"href":"https:\/\/byso.top\/index.php?rest_route=\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byso.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byso.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byso.top\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/byso.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=144"}],"version-history":[{"count":3,"href":"https:\/\/byso.top\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/byso.top\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions\/148"}],"wp:attachment":[{"href":"https:\/\/byso.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byso.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byso.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}