Fix DNS resolution issues
This commit is contained in:
@@ -27,6 +27,16 @@ function joinArgs(parts: (string | undefined)[]) {
|
|||||||
return parts.filter(Boolean).join(" ");
|
return parts.filter(Boolean).join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deriveGatewayIp(cidr?: string): string | undefined {
|
||||||
|
if (!cidr) return undefined;
|
||||||
|
const ip = cidr.split("/")[0];
|
||||||
|
if (!ip) return undefined;
|
||||||
|
const parts = ip.split(".");
|
||||||
|
if (parts.length !== 4) return undefined;
|
||||||
|
// Assume host/gateway is .1 on the subnet
|
||||||
|
return `${parts[0]}.${parts[1]}.${parts[2]}.1`;
|
||||||
|
}
|
||||||
|
|
||||||
function protocolsForRule({
|
function protocolsForRule({
|
||||||
protocol,
|
protocol,
|
||||||
has_ports,
|
has_ports,
|
||||||
@@ -165,6 +175,7 @@ export default function buildHostIptablesScripts({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scoped_subnet = host_subnet?.trim();
|
const scoped_subnet = host_subnet?.trim();
|
||||||
|
const host_wg_ip = deriveGatewayIp(scoped_subnet);
|
||||||
|
|
||||||
if (scoped_subnet && !validateIpv4Cidr({ value: scoped_subnet })) {
|
if (scoped_subnet && !validateIpv4Cidr({ value: scoped_subnet })) {
|
||||||
return {
|
return {
|
||||||
@@ -175,8 +186,10 @@ export default function buildHostIptablesScripts({
|
|||||||
|
|
||||||
const { forward, input } = deriveIptablesChainNames({ host_id });
|
const { forward, input } = deriveIptablesChainNames({ host_id });
|
||||||
|
|
||||||
const masquerade_match = scoped_subnet ? `-s ${scoped_subnet} ` : ``;
|
const masquerade_match = scoped_subnet ? `-s ${scoped_subnet}` : ``;
|
||||||
const accept_lines: string[] = [];
|
const accept_lines: string[] = [
|
||||||
|
`iptables -A ${forward} -o ${interface_name} -j DROP`,
|
||||||
|
];
|
||||||
const host_clients = clients || [];
|
const host_clients = clients || [];
|
||||||
|
|
||||||
for (let i = 0; i < host_clients.length; i++) {
|
for (let i = 0; i < host_clients.length; i++) {
|
||||||
@@ -224,8 +237,8 @@ export default function buildHostIptablesScripts({
|
|||||||
if (rule.rule_type == "all") {
|
if (rule.rule_type == "all") {
|
||||||
accept_lines.push(
|
accept_lines.push(
|
||||||
`iptables -A ${forward} -s ${source} -j ACCEPT`,
|
`iptables -A ${forward} -s ${source} -j ACCEPT`,
|
||||||
scoped_subnet
|
host_wg_ip
|
||||||
? `iptables -A ${input} -s ${source} -d ${scoped_subnet} -j ACCEPT`
|
? `iptables -A ${input} -s ${source} -d ${host_wg_ip} -j ACCEPT`
|
||||||
: `iptables -A ${input} -s ${source} -j ACCEPT`,
|
: `iptables -A ${input} -s ${source} -j ACCEPT`,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -252,17 +265,12 @@ export default function buildHostIptablesScripts({
|
|||||||
source,
|
source,
|
||||||
protocol: rule.protocol || "any",
|
protocol: rule.protocol || "any",
|
||||||
ports: parsed_ports.ports,
|
ports: parsed_ports.ports,
|
||||||
host_wg_ip: scoped_subnet,
|
host_wg_ip,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accept_lines.push(
|
|
||||||
`# Prevent clients from forwarding traffic back into the WireGuard network`,
|
|
||||||
`iptables -A ${forward} -o ${interface_name} -j DROP`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const post_up = [
|
const post_up = [
|
||||||
`#!/bin/bash`,
|
`#!/bin/bash`,
|
||||||
``,
|
``,
|
||||||
|
|||||||
Reference in New Issue
Block a user