How to use V2ray to set up a Local DNS
Download and install v2ray
cd ~/Downloads
wget https://github.com/v2fly/v2ray-core/releases/download/v5.1.0/v2ray-linux-arm64-v8a.zip
# uncompress the file, and use pwd to get the path
export PATH="$HOME/Downloads/v2ray:$PATH"
source ~/.bashrc
Create the v2ray config file
//v2ray_config.json
{
"dns": {
"hosts": {
"domain:googleapis.cn": "googleapis.com",
"domain:weloveparty.domain.local": "10.0.2.2" //"192.168.49.195"
},
"servers": [
"8.8.8.8",
"1.1.1.1",
{
"address": "223.5.5.5",
"domains": [
"geosite:cn"
],
"expectIPs": [
"geoip:cn"
],
"port": 53
}
]
},
"inbounds": [
{
"listen": "127.0.0.1",
"port": 10807,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true,
"userLevel": 8
},
"tag": "socks"
},
{
"listen": "127.0.0.1",
"port": 10808,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true,
"userLevel": 8
},
"tag": "tun2socks" //"socks"
},
{
"listen": "127.0.0.1",
"port": 10809,
"protocol": "http",
"tag": "http"
},
{
"listen": "127.0.0.1",
"port": 22244,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "fe186f9d-2e99-37a2-b30f-252d11337dc2",
"alterId": 0,
"security": "none"
}
]
},
"streamSettings": {
"network": "ws"
},
"mux": {
"enabled": true
}
},
{
"listen": "127.0.0.1",
"port": 22245, // The open port
"protocol": "dokodemo-door",
"settings": {
"network": "tcp,udp",
"followRedirect": true // Need to be set as true to accept traffic from iptables
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
}
}
],
"log": {
"loglevel": "warning"
},
"outbounds": [
//{
// "protocol": "socks",
// "settings": {
// "servers": [
// {
// "address": "127.0.0.1",
// "port": 10808
// }
// ]
// }
// "tag": "proxy"
//},
{
"mux": {
"concurrency": 8,
"enabled": false
},
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "144.202.109.163", //"10.0.2.2",
"port": 1310,
"users": [
{
"alterId": 0,
"encryption": "",
"flow": "",
"id": "fe786f9d-8e99-47a2-b30f-252d11337dc6",
"level": 8,
"security": "none"
}
]
}
]
},
"streamSettings": {
"network": "ws",
"security": "",
"wsSettings": {
"headers": {
"Host": ""
},
"path": ""
}
},
"tag": "proxy"
},
//{
// "protocol": "freedom",
// "settings": {
// "domainStrategy": "UseIP"
// },
// "tag": "proxy"
//},
{
"protocol": "freedom",
"settings": {
"domainStrategy": "UseIP"
},
"tag": "direct"
},
{
"protocol": "blackhole",
"settings": {
"response": {
"type": "http"
}
},
"tag": "block"
}
],
"routing": {
"domainMatcher": "mph",
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"ip": [
"8.8.8.8"
],
"outboundTag": "proxy",
"port": "53",
"type": "field"
},
{
"ip": [
"1.1.1.1"
],
"outboundTag": "proxy",
"port": "53",
"type": "field"
},
{
"ip": [
"223.5.5.5"
],
"outboundTag": "direct",
"port": "53",
"type": "field"
},
{
"ip": [
"geoip:private"
],
"outboundTag": "direct",
"type": "field"
}
]
}
}
Run v2ray
v2ray run -c v2ray_config.json
For Android Studio simulator
After turn off the WiFi,
You have to use Kitsunebi
(a v2ray core wrapper) to import the v2ray config again.
Then start a global VPN.
Use HTTP proxy
It’s in WiFi advanced setting.
127.0.0.1:10809
More info
yingshaoxo: For some reason, I don’t know why v2ray got two versions of documents, one is Chinese, another is English. And the Chinese version of the docs is clearly different than the English version.
https://www.v2fly.org/en_US/config/dns.html#dnsobject
https://www.v2fly.org/config/dns.html#dnsobject
https://guide.v2fly.org/en_US/app/transparent_proxy.html#preparation
By the way, you could use the
/etc/hosts
to do the same thing:127.0.0.1 ggboy.domain.local find_a_girlfriend.ggboy.domain.local