Let's suppose the following:
network: version: 2 renderer: networkd ethernets: enp7s0: dhcp4: no addresses: [192.168.1.1/24] gateway4: 1.2.3.4 nameservers: addresses: [8.8.8.8] routes: - to: 192.168.1.0/24 via: 192.168.1.1 metric: 100
then run:
netplan generate netplan apply
/etc/sysctl.conf
Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1
then run:
sysctl -p
add the following in /etc/ufw/before.rules BEFORE the *filter rules
# NAT table rules *nat :POSTROUTING ACCEPT [0:0] -A POSTROUTING -s 192.168.34.0/24 -o enp2s0 -j MASQUERADE COMMIT
Note, that each section must be between:
*tablename
...
COMMIT
Make sure your firewall allows the traffic needed.
For example ufw:
~$ sudo ufw status verbose Status: active Logging: on (low) Default: deny (incoming), allow (outgoing), deny (routed) New profiles: skip ...