2021-12-03

Linux - forwarding IP traffic while masquerading the source IP address

# the script arguments are:

# $1 is "I" for insert the masquerade in the table before all other iptables enteries

# $2 is the source IP address to be masqueraded be it a specific address "10.11.11.3" or "10.11.11.0/24"

# this is particularly useful for openvpn connections

/usr/sbin/sysctl -w net.ipv4.ip_forward=1

/usr/sbin/sysctl -w net.ipv6.conf.all.forwarding=1

iptables --table nat -$1 POSTROUTING -s $2 -j MASQUERADE

No comments:

Post a Comment

Linux NetworkManager command line configuration

 Configure Network Settings Using Network Manager in Linux Last updated: March 25, 2025 Written by:baeldung Network ConfigurationNetworkMana...