Recipe 2.1 Enabling Source Address Verification2.1.1 Problem
You want to prevent remote
2.1.2 SolutionTurn on source address verification in the kernel. Place the following code into a system boot file (i.e., linked into the /etc/rc.d hierarchy) that executes before any network devices are enabled: #!/bin/sh echo -n "Enabling source address verification..." echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter echo "done" Or, to perform the same task after network devices are enabled:
#!/bin/sh
CONF_DIR=/proc/sys/net/ipv4/conf
CONF_FILE=rp_filter
if [ -e ${CONF_DIR}/all/${CONF_FILE} ]; then
echo -n "Setting up IP spoofing protection..."
for f in ${CONF_DIR}/*/${CONF_FILE}; do
echo 1 > $f
done
echo "done"
fi
A quicker method may be to add this line to /etc/sysctl.conf : net.ipv4.conf.all.rp_filter = 1 and run sysctl to reread the configuration immediately: # sysctl -p 2.1.3 Discussion
Source address verification is a kernel-level feature that
2.1.4 See Alsosysctl(8). Source address verification is explained in the IPCHAINS-HOWTO at http://www.linux.org/docs/ldp/howto/IPCHAINS-HOWTO-5.html#ss5.7. |
Recipe 2.2 Blocking Spoofed Addresses2.2.1 Problem
You want to prevent remote
2.2.2 SolutionFor a single machine, to prevent remote hosts from pretending to be that machine, use the following: For iptables : # iptables -A INPUT -i external_interface -s your_IP_address -j REJECT For ipchains : # ipchains -A input -i external_interface -s your_IP_address -j REJECT If you have a Linux machine acting as a firewall for your internal network (say, 192.168.0.*) with two network interfaces, one internal and one external, and you want to prevent remote machines from spoofing internal IP addresses to the external interface, use the following: For iptables : # iptables -A INPUT -i external_interface -s 192.168.0.0/24 -j REJECT
For ipchains : # ipchains -A input -i external_interface -s 192.168.0.0/24 -j REJECT 2.2.3 DiscussionFor a single machine, simply enable source address verification in the kernel. [Recipe 2.1] 2.2.4 See Alsoiptables(8), ipchains(8). |