WG inbound set DNS

This commit is contained in:
SilverPolarFox 2026-04-27 20:25:15 +03:00
parent 0b5c239f98
commit 48ad787f45
2 changed files with 28 additions and 5 deletions

View file

@ -2179,10 +2179,14 @@ class Inbound extends XrayCommonClass {
} }
getWireguardTxt(address, port, remark, peerId) { getWireguardTxt(address, port, remark, peerId) {
<<<<<<< HEAD
const DNS = this.settings.DNS || '1.1.1.1, 1.0.0.1';
=======
>>>>>>> 0b5c239f98fd112df10ed4846377563a391ebf60
let txt = `[Interface]\n` let txt = `[Interface]\n`
txt += `PrivateKey = ${this.settings.peers[peerId].privateKey}\n` txt += `PrivateKey = ${this.settings.peers[peerId].privateKey}\n`
txt += `Address = ${this.settings.peers[peerId].allowedIPs[0]}\n` txt += `Address = ${this.settings.peers[peerId].allowedIPs[0]}\n`
txt += `DNS = 1.1.1.1, 1.0.0.1\n` txt += `DNS = ${DNS}\n`
if (this.settings.mtu) { if (this.settings.mtu) {
txt += `MTU = ${this.settings.mtu}\n` txt += `MTU = ${this.settings.mtu}\n`
} }
@ -3035,7 +3039,8 @@ Inbound.WireguardSettings = class extends XrayCommonClass {
mtu = 1420, mtu = 1420,
secretKey = Wireguard.generateKeypair().privateKey, secretKey = Wireguard.generateKeypair().privateKey,
peers = [new Inbound.WireguardSettings.Peer()], peers = [new Inbound.WireguardSettings.Peer()],
noKernelTun = false noKernelTun = false,
DNS = '1.1.1.1, 1.0.0.1'
) { ) {
super(protocol); super(protocol);
this.mtu = mtu; this.mtu = mtu;
@ -3043,10 +3048,15 @@ Inbound.WireguardSettings = class extends XrayCommonClass {
this.pubKey = secretKey.length > 0 ? Wireguard.generateKeypair(secretKey).publicKey : ''; this.pubKey = secretKey.length > 0 ? Wireguard.generateKeypair(secretKey).publicKey : '';
this.peers = peers; this.peers = peers;
this.noKernelTun = noKernelTun; this.noKernelTun = noKernelTun;
this.DNS = DNS;
this.peers.forEach(peer => {
peer.DNS = this.DNS;
});
} }
addPeer() { addPeer() {
this.peers.push(new Inbound.WireguardSettings.Peer(null, null, '', ['10.0.0.' + (this.peers.length + 2)])); this.peers.push(new Inbound.WireguardSettings.Peer(null, null, '', ['10.0.0.' + (this.peers.length + 2)], 0, this.DNS));
} }
delPeer(index) { delPeer(index) {
@ -3060,6 +3070,7 @@ Inbound.WireguardSettings = class extends XrayCommonClass {
json.secretKey, json.secretKey,
json.peers.map(peer => Inbound.WireguardSettings.Peer.fromJson(peer)), json.peers.map(peer => Inbound.WireguardSettings.Peer.fromJson(peer)),
json.noKernelTun, json.noKernelTun,
json.DNS,
); );
} }
@ -3069,12 +3080,13 @@ Inbound.WireguardSettings = class extends XrayCommonClass {
secretKey: this.secretKey, secretKey: this.secretKey,
peers: Inbound.WireguardSettings.Peer.toJsonArray(this.peers), peers: Inbound.WireguardSettings.Peer.toJsonArray(this.peers),
noKernelTun: this.noKernelTun, noKernelTun: this.noKernelTun,
DNS: this.DNS,
}; };
} }
}; };
Inbound.WireguardSettings.Peer = class extends XrayCommonClass { Inbound.WireguardSettings.Peer = class extends XrayCommonClass {
constructor(privateKey, publicKey, psk = '', allowedIPs = ['10.0.0.2/32'], keepAlive = 0) { constructor(privateKey, publicKey, psk = '', allowedIPs = ['10.0.0.2/32'], keepAlive = 0, DNS = '1.1.1.1, 1.0.0.1') {
super(); super();
this.privateKey = privateKey this.privateKey = privateKey
this.publicKey = publicKey; this.publicKey = publicKey;
@ -3087,6 +3099,7 @@ Inbound.WireguardSettings.Peer = class extends XrayCommonClass {
}) })
this.allowedIPs = allowedIPs; this.allowedIPs = allowedIPs;
this.keepAlive = keepAlive; this.keepAlive = keepAlive;
this.DNS = DNS;
} }
static fromJson(json = {}) { static fromJson(json = {}) {
@ -3095,7 +3108,8 @@ Inbound.WireguardSettings.Peer = class extends XrayCommonClass {
json.publicKey, json.publicKey,
json.preSharedKey, json.preSharedKey,
json.allowedIPs, json.allowedIPs,
json.keepAlive json.keepAlive,
json.DNS
); );
} }
@ -3109,6 +3123,7 @@ Inbound.WireguardSettings.Peer = class extends XrayCommonClass {
preSharedKey: this.psk.length > 0 ? this.psk : undefined, preSharedKey: this.psk.length > 0 ? this.psk : undefined,
allowedIPs: this.allowedIPs, allowedIPs: this.allowedIPs,
keepAlive: this.keepAlive ?? undefined, keepAlive: this.keepAlive ?? undefined,
DNS: this.DNS,
}; };
} }
}; };

View file

@ -19,6 +19,10 @@
<a-form-item label='MTU'> <a-form-item label='MTU'>
<a-input-number v-model.number="inbound.settings.mtu"></a-input-number> <a-input-number v-model.number="inbound.settings.mtu"></a-input-number>
</a-form-item> </a-form-item>
<a-form-item label='DNS'>
<a-input v-model.trim="inbound.settings.DNS" placeholder="1.1.1.1, 1.0.0.1">
</a-input>
</a-form-item>
<a-form-item label='No Kernel Tun'> <a-form-item label='No Kernel Tun'>
<a-switch v-model="inbound.settings.noKernelTun"></a-switch> <a-switch v-model="inbound.settings.noKernelTun"></a-switch>
</a-form-item> </a-form-item>
@ -74,6 +78,10 @@
</a-input> </a-input>
</template> </template>
</a-form-item> </a-form-item>
<a-form-item label='Peer DNS'>
<a-input v-model.trim="peer.DNS">
</a-input>
</a-form-item>
<a-form-item label='Keep Alive'> <a-form-item label='Keep Alive'>
<a-input-number v-model.number="peer.keepAlive" :min="0"></a-input-number> <a-input-number v-model.number="peer.keepAlive" :min="0"></a-input-number>
</a-form-item> </a-form-item>