0

Update firewall rules

by
Published Oct 17, 2025

Updates the inbound and outbound Rules for a Firewall.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Update firewall rules
7
 * Updates the inbound and outbound Rules for a Firewall.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  firewallId: string,
13
  body: {
14
    fingerprint?: string;
15
    inbound?: {
16
      action?: "ACCEPT" | "DROP";
17
      addresses?: { ipv4?: string[]; ipv6?: string[] };
18
      description?: string;
19
      label?: string;
20
      ports?: string;
21
      protocol?: "TCP" | "UDP" | "ICMP" | "IPENCAP";
22
    }[];
23
    inbound_policy?: "ACCEPT" | "DROP";
24
    outbound?: {
25
      action?: "ACCEPT" | "DROP";
26
      addresses?: { ipv4?: string[]; ipv6?: string[] };
27
      description?: string;
28
      label?: string;
29
      ports?: string;
30
      protocol?: "TCP" | "UDP" | "ICMP" | "IPENCAP";
31
    }[];
32
    outbound_policy?: "ACCEPT" | "DROP";
33
    version?: number;
34
  } & { inbound?: {}; outbound?: {} },
35
) {
36
  const url = new URL(
37
    `https://api.linode.com/${apiVersion}/networking/firewalls/${firewallId}/rules`,
38
  );
39

40
  const response = await fetch(url, {
41
    method: "PUT",
42
    headers: {
43
      "Content-Type": "application/json",
44
      Authorization: "Bearer " + auth.token,
45
    },
46
    body: JSON.stringify(body),
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54