Although I asked ITSC for all of Nanjing University’s IP address ranges, they refused to provide them. /_ \
Since I’ve obtained authorization from PureZhi, I can now update the IP ranges here daily (though PureZhi itself does not update daily—dates will be specified below). ||There’s probably no real need to do this daily, but since it’s automated, I love automation.
Your IP is, region:,.
| start | end | mask | mask_len | region |
|---|
IP location data provided by PureZhi CZ88
Check the source IP address. If it belongs to Nanjing University, redirect to the internal server.
Define geo in /etc/nginx/nginx.conf:
http {
...
geo $njuip {
default 0;
58.192.32.0/20 1;
58.192.48.0/21 1;
58.193.224.0/19 1;
58.240.127.3 1;
114.212.0.0/16 1;
180.209.0.0/20 1;
202.38.2.0/23 1;
202.119.32.0/19 1;
210.28.128.0/20 1;
210.29.240.0/20 1;
218.94.9.35 1;
218.94.9.36/31 1;
218.94.9.38 1;
218.94.36.211 1;
218.94.142.6 1;
219.219.112.0/20 1;
221.226.2.0/25 1;
221.226.2.128/27 1;
221.226.2.160/28 1;
221.226.2.176/29 1;
221.226.2.184/31 1;
221.226.2.186 1;
221.226.2.187 1;
221.226.2.188/30 1;
221.226.2.192/26 1;
221.226.3.0/28 1;
221.226.3.16/29 1;
221.226.3.24/31 1;
221.226.3.27 1;
221.226.3.28/30 1;
221.226.3.32/27 1;
221.226.3.64/26 1;
221.226.3.128/25 1;
}
...
}
Use in the server block requiring redirection:
Note: I have abandoned OpenVPN in favor of ZeroTier. This configuration is not guaranteed to work.
Determine whether the destination address is a Nanjing University address. Only route through VPN when accessing resources from within the university.
Add the following lines under dev tun in your existing .ovpn file, removing the # comment symbol:
# filecodebox
server {
...
server_name example.com;
location / {
if ($njuip) {
return 302 https://nju.example.com$request_uri;
}
...
}
}
route-nopull # Do not use routes pushed by the server
route 10.8.0.0 255.255.0.0 vpn_gateway # Should be changed to your OpenVPN client subnet
route 172.26.0.0 255.255.128.0 vpn_gateway # Internal network segment
route 10.4.128.0 255.255.224.0 vpn_gateway # Internal network segment
route 58.192.32.0 255.255.240.0 vpn_gateway
route 58.192.48.0 255.255.248.0 vpn_gateway
route 58.193.224.0 255.255.224.0 vpn_gateway
route 58.240.127.3 255.255.255.255 vpn_gateway
route 114.212.0.0 255.255.0.0 vpn_gateway
route 180.209.0.0 255.255.240.0 vpn_gateway
route 202.38.2.0 255.255.254.0 vpn_gateway
route 202.119.32.0 255.255.224.0 vpn_gateway
route 210.28.128.0 255.255.240.0 vpn_gateway
route 210.29.240.0 255.255.240.0 vpn_gateway
route 218.94.9.35 255.255.255.255 vpn_gateway
route 218.94.9.36 255.255.255.254 vpn_gateway
route 218.94.9.38 255.255.255.255 vpn_gateway
route 218.94.36.211 255.255.255.255 vpn_gateway
route 218.94.142.6 255.255.255.255 vpn_gateway
route 219.219.112.0 255.255.240.0 vpn_gateway
route 221.226.2.0 255.255.255.128 vpn_gateway
route 221.226.2.128 255.255.255.224 vpn_gateway
route 221.226.2.160 255.255.255.240 vpn_gateway
route 221.226.2.176 255.255.255.248 vpn_gateway
route 221.226.2.184 255.255.255.254 vpn_gateway
route 221.226.2.186 255.255.255.255 vpn_gateway
route 221.226.2.187 255.255.255.255 vpn_gateway
route 221.226.2.188 255.255.255.252 vpn_gateway
route 221.226.2.192 255.255.255.192 vpn_gateway
route 221.226.3.0 255.255.255.240 vpn_gateway
route 221.226.3.16 255.255.255.248 vpn_gateway
route 221.226.3.24 255.255.255.254 vpn_gateway
route 221.226.3.27 255.255.255.255 vpn_gateway
route 221.226.3.28 255.255.255.252 vpn_gateway
route 221.226.3.32 255.255.255.224 vpn_gateway
route 221.226.3.64 255.255.255.192 vpn_gateway
route 221.226.3.128 255.255.255.128 vpn_gateway