{"id":417,"date":"2024-09-26T23:38:44","date_gmt":"2024-09-26T15:38:44","guid":{"rendered":"https:\/\/www.feeek.com\/?p=417"},"modified":"2024-09-30T05:06:53","modified_gmt":"2024-09-29T21:06:53","slug":"wireguard-%e6%8e%92%e9%99%a4ip%e5%be%97%e5%88%b0%e5%85%81%e8%ae%b8%e5%88%97%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/www.feeek.com\/?p=417","title":{"rendered":"Wireguard \u2013 \u6392\u9664IP\u5f97\u5230\u5141\u8bb8\u5217\u8868"},"content":{"rendered":"\n<p>By AllowedIPs in the wireguard configuration file, you mean which IPs should be routed through the wireguard tunnel. So if you want to exclude a single IP address from these allowed IP addresses, all IP networks must be enabled except for that single IP(s)<\/p>\n\n\n\n<p>The easiest way to do this is with a Pyhton script:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">from ipaddress import ip_network\n\nstart = '0.0.0.0\/0'\nexclude = ['IP1REFREE', 'IP2REFREE']\n\nresult = [ip_network(start)]\nfor x in exclude:\n    n = ip_network(x)\n    new = []\n    for y in result:\n        if y.overlaps(n):\n            new.extend(y.address_exclude(n))\n        else:\n            new.append(y)\n    result = new\n\nprint(','.join(str(x) for x in sorted(result)))<\/pre>\n\n\n\n<p>Save this script as a +.py file and then you can run it, for example, like this (on Linux):<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">python3 subnets.py<\/pre>\n\n\n\n<p>You can then enter the result after \u201cAllowedIPs =\u201d.<\/p>\n\n\n\n<p>\u53c2\u8003\u539f\u6587\uff1a<a href=\"https:\/\/www.lautenbacher.io\/en\/lamp-en\/wireguard-exclude-a-single-ip-address\/\">https:\/\/www.lautenbacher.io\/en\/lamp-en\/wireguard-exclude-a-single-ip-address\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By AllowedIPs in the wireguard configuration file, you  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-417","post","type-post","status-publish","format-standard","hentry","category-tech"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.feeek.com\/index.php?rest_route=\/wp\/v2\/posts\/417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.feeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.feeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.feeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.feeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=417"}],"version-history":[{"count":4,"href":"https:\/\/www.feeek.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/www.feeek.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/www.feeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.feeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.feeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}