How to add a default gateway and enable IP forwarding on Ubuntu

Summary

This article show you how to add a default gateway to Ubuntu and how to enable IP forwarding. IP forwarding in this instance is also known at source NAT and allows your Ubuntu machine to act as a router.

How to add a default gateway to Ubuntu Linux

Here are two possible way of doing it.

The first one is more native and will be available on most Debian based systems. The second one might need to have a specific library installed.

ip route add default via 192.168.56.1

or

route add default gw 192.168.56.1

How to Enable IP Forwarding on Ubuntu

The command to enable IP forwarding is

sudo sysctl net.ipv4.ip_forward=1

To check the setting

sudo sysctl net.ipv4.ip_forward=1

References

 

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top