What does every part of this command mean?
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
From the manual pages of iptables(8)
:
iptables
:
Iptables and ip6tables are used to set up, maintain, and inspect the tables of IPv4 and IPv6 packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains.
-t nat
:
Iptables and ip6tables are used to set up, maintain, and inspect the tables of IPv4 and IPv6 packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains.
This table is consulted when a packet that creates a new connection is encountered. It consists of three built-ins: PREROUTING (for altering packets as soon as they come in), OUTPUT (for altering locally-generated packets before routing), and POSTROUTING (for altering packets as they are about to go out). IPv6 NAT support is available since kernel 3.7.
-A POSTROUTING
:
Append one or more rules to the end of the selected chain. When the source and/or destination names resolve to more than one address, a rule will be added for each possible address combination.
-o eth0
: (eth0 is:)
Name of an interface via which a packet is going to be sent (for packets entering the FORWARD, OUTPUT and POSTROUTING chains). When the "!" argument is used before the interface name, the sense is inverted. If the interface name ends in a "+", then any interface which begins with this name will match. If this option is omitted, any interface name will match.
-j MASQUERADE
:
This specifies the target of the rule; i.e., what to do if the packet matches it. The target can be a user-defined chain (other than the one this rule is in), one of the special builtin targets which decide the fate of the packet immediately, or an extension (see EXTENSIONS below). If this option is omitted in a rule (and -g is not used), then matching the rule will have no effect on the packet's fate, but the counters on the rule will be incremented.
sudo
: It stands for “super user do!” as a Linux system administrator or power user, it’s one of the most important commands.
iptables
: Is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel.
-t
: This option specifies the packet matching table which the command should operate on.
nat
: This table is consulted when a packet that creates a new connection is encountered.
-A
: Append one or more rules to the end of the selected chain.
POSTROUTING
: One of three built-ins of nat, for altering packets as they are about to go out.
-o eth0
: Name of an interface via which a packet is going to be sent.
-j MASQUERADE
: This specifies the target of the rule; i.e., what to do if the packet matches it.
man sudo
andman iptables