ip-restriction
Single IPs, multiple IPs or even IP ranges in CIDR notation like 10.10.10.0/24
can be used.
note
Either one of whitelist
or blacklist
attribute must be specified. They cannot be used together.
To return a custom message when an IP address is not allowed access, configure it in the Plugin as shown below:
"plugins": {
"ip-restriction": {
"whitelist": [
"113.74.26.106/24"
],
}
}
After you have configured the Plugin as shown above, when you make a request from the IP 127.0.0.1
:
HTTP/1.1 200 OK
...
HTTP/1.1 403 Forbidden
...
To change the whitelisted/blacklisted IPs, you can update the Plugin configuration. The changes are hot reloaded and there is no need to restart the service.
To disable the Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.
curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/index.html",
"plugins": {},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}'