The 5 parameters that allow_standard_protocol takes are, in order of appearence:
The port. This parameter is the only mandatory parameter.
The protocol (tcp, udp or all)
The source IP address or network (default: 0/0)
The destination IP address or network (default: 0/0)
The chain this rule should be in (default: INPUT)
The additional parameter, environment variable CURRENT_PREFERRED_TARGET allows you to influence the jump target, despite the definition of any additional parameters. By default, the jump target is ACCEPT.
Suppose you wanted to allow MySQL connections to the node.
Suppose you do not really care about the source or destination IP address or network. The call to allow_standard_protocol() would look as follows:
allow_standard_protocol "3306" "tcp"
Now suppose you do in fact care about the source or destination IP address or network. Suppose you want to allow network 192.168.1.0/24, and only to IP address 10.0.0.10, which is the IP address the MySQL server is listening on. The call to allow_standard_protocol() would look as follows:
allow_standard_protocol "3306" "tcp" "192.168.1.0/24" "10.0.0.10"
In addition, you could blacklist one of the IP addresses in network 192.168.1.0/24, such as 192.168.1.10, by prepending the following line:
env CURRENT_PREFERRED_TARGET=DROP allow_standard_protocol \
"3306" "tcp" "192.168.1.10" "10.0.0.10"
The myhosts_chain() function uses the command getent hosts to obtain a list of hosts. As such, in order to use the myhosts_chain() function, your nameservice switching needs to be properly configured, including /etc/hosts. This function though creates the opportunity to take a list from NIS(+) or LDAP, and as such allows you to centrally administer your list of hosts and reuse that list in iptables.
At the end of the myhosts chain, a rule is appended to reject all other traffic.
Suppose you administer a list of hosts through LDAP, and the system has been configured (through /etc/nsswitch.conf) to obtain hosts from LDAP as well (besides files and dns, for example).
The command getent hosts will return a list of all entries in /etc/hosts and LDAP, and the myhosts_chain() function populates the myhosts chain with IP address of hosts you know and care about.
Now suppose that you want your webserver to only be available for hosts you know. You would use a set of lines similar to:
export CURRENT_PREFERRED_TARGET=myhosts
allow_http
allow_https
unset CURRENT_PREFERRED_TARGET
The result will be similar to:
# iptables -L -n
Chain INPUT (policy DROP 0 packets, 0 bytes)
target prot opt in out source destination
ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
whitelist all -- * * 0.0.0.0/0 0.0.0.0/0
blacklist all -- * * 0.0.0.0/0 0.0.0.0/0
tcpflags all -- * * 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp dpt:22 state NEW,ESTABLISHED
myhosts all -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp dpt:80 state NEW,ESTABLISHED
myhosts all -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp dpt:443 state NEW,ESTABLISHED
ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp state RELATED,ESTABLISHED
ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 \
udp state RELATED,ESTABLISHED
ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
Chain myhosts (2 references)
target prot opt in out source destination
ACCEPT all -- * * myhost1 0.0.0.0/0
ACCEPT all -- * * myhost2 0.0.0.0/0
REJECT all -- * * 0.0.0.0/0 0.0.0.0/0
(more output abbreviated)
The mysubnets_chain() function uses the command getent networks to obtain a list of networks. As such, in order to use the mysubnets_chain() function, your nameservice switching needs to be properly configured, including /etc/networks. This function though creates the opportunity to take a list from NIS(+) or LDAP, and as such allows you to centrally administer your list of networks and reuse that list in iptables.
At the end of the myhosts chain, a rule is appended to reject all other traffic.
Suppose you administer a list of networks through LDAP, and the system has been configured (through /etc/nsswitch.conf) to obtain networks from LDAP as well (besides just files, for example).
The command getent networks will return a list of all entries in /etc/networks and LDAP, and the mysubnets_chain() function populates the mysubnets chain with IP address of networks you know and care about.
Now suppose that you want your webserver to only be available for networks you know. You would use a set of lines similar to:
export CURRENT_PREFERRED_TARGET=mysubnets
allow_http
allow_https
unset CURRENT_PREFERRED_TARGET
The result will be similar to:
# iptables -L -n
Chain INPUT (policy DROP 0 packets, 0 bytes)
target prot opt in out source destination
ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
whitelist all -- * * 0.0.0.0/0 0.0.0.0/0
blacklist all -- * * 0.0.0.0/0 0.0.0.0/0
tcpflags all -- * * 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp dpt:22 state NEW,ESTABLISHED
mysubnets all -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp dpt:80 state NEW,ESTABLISHED
mysubnets all -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp dpt:443 state NEW,ESTABLISHED
ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 \
tcp state RELATED,ESTABLISHED
ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 \
udp state RELATED,ESTABLISHED
ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
Chain mysubnets (2 references)
target prot opt in out source destination
ACCEPT all -- * * mynetwork1 0.0.0.0/0
ACCEPT all -- * * mynetwork2 0.0.0.0/0
REJECT all -- * * 0.0.0.0/0 0.0.0.0/0
(more output abbreviated)