1. Enable packet forwarding for IPv4 between NICs:
- Open and edit /etc/sysctl.conf
- Ucomment net.ipv4.ip_forward=1
- To execute command sysctl -p
- iptables -t nat -A POSTROUTING -o enp0s8 -s 192.168.1.0/24 -j MASQUERADE
- Where enp0s8 is WAN and 192.168.1.0/24 is LAN, please modify those parameters depend on your environment.
- Save rules: iptables-save > /etc/iptables.save
- Restore rules:
- Open and edit /etc/network/interfaces to add pre-up.....
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet static
address 192.168.1.254
netmask 255.255.255.0
pre-up iptables-restore < /etc/iptables.save
Done~