Skip to main content

Command Palette

Search for a command to run...

๐Ÿ”„ How to Enable IP Forwarding on Debian 12 (Bookworm) ๐Ÿš€

Learn how to enable IP forwarding on Debian 12 for routers and VPNs

Updated
๐Ÿ”„ How to Enable IP Forwarding on Debian 12 (Bookworm) ๐Ÿš€
R

Driving SD-WAN Adoption in South Africa

If youโ€™re setting up a router, a VPN gateway, or just need your Debian 12 (Bookworm) machine to forward packets between interfaces, youโ€™ll need to enable IP forwarding.

By default, Debian does not forward packets, but enabling it is straightforward. Letโ€™s dive in! ๐ŸŠโ€โ™‚๏ธ


๐Ÿ›  Step 1: Temporarily Enable IP Forwarding

If you want to enable IPv4 forwarding for the current session (without making it permanent), run:

sudo sysctl -w net.ipv4.ip_forward=1

๐Ÿ”น Note: These changes will disappear after a reboot! To make them permanent, proceed to Step 2.


๐Ÿ“„ Step 2: Make IP Forwarding Permanent

To ensure IP forwarding is always enabled after reboots, we modify the sysctl configuration file.

๐Ÿ”ง Enable IPv4 Forwarding Permanently

1๏ธโƒฃ Open the sysctl configuration file:

sudo nano /etc/sysctl.conf

2๏ธโƒฃ Find this line (or add it if it doesnโ€™t exist):

net.ipv4.ip_forward=1
net.netfilter.nf_conntrack_max=1048576

3๏ธโƒฃ Save the file (Ctrl + X, then Y, then Enter).


๐Ÿ”„ Step 3: Apply Changes Without Rebooting

Instead of restarting the system, apply the new settings immediately:

sudo sysctl -p

๐Ÿ”ฅ Step 4: Verify That Forwarding is Enabled

You can check if forwarding is active using:

cat /proc/sys/net/ipv4/ip_forward

It should return 1 if enabled.


๐Ÿ›ก Step 5: Adjust Firewall Rules (If Needed)

If youโ€™re using nftables, ensure your firewall allows forwarding.

For nftables, use something like:

nft add rule ip filter forward accept

โœ… Wrap

Thatโ€™s it! ๐ŸŽ‰ Your Debian 12 (Bookworm) machine is now forwarding packets like a pro. ๐Ÿš€ Whether youโ€™re setting up a router, VPN gateway, or multi-interface server, youโ€™re good to go!

Happy networking! ๐ŸŒ๐Ÿ”ฅ


Bonus: To enable IP forwarding on a Windows servers go to the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters. If not already there, create a new REG_DWORD value named IPEnableRouter. Set IPEnableRouter to 1 and reboot. Packet forwarding should now be enabled.