Whitelist allowed IPs (in/out) using iptables

Solution 1:

I'd suggest grabbing a firewall configuration tool, such a Firestarter, and going from there. Here are some basics for you, though.

#Flush existing rules
iptables -F
# Set up default DROP rule for eth0
iptables -P INPUT DROP
# Allow existing connections to continue
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Accept everything from the 192.168.1.x network
iptables -A INPUT -i eth0 -s 192.168.1.0/24 -j ACCEPT
# Allow connections from this host to 192.168.2.10
iptables -A OUTPUT -o eth0 -d 192.168.2.10 -j ACCEPT

Solution 2:

iptables -I INPUT -s <allowed_ip> -j ACCEPT #(repeat this line as needed)
iptables -P INPUT DROP

This will turn your system into a non-existent system for non-allowed computers.