Most Linux distributions will use IPTables as the default firewall.
Here are the commands to whitelist an IP address on your Linux server, both incoming and outgoing.
Example: How to whitelist IP address 192.168.0.1
Step 1: Log into the server via SSH.
Step 2: Allow incoming connections from 192.168.0.1
# iptables -A INPUT -s 192.168.0.1 -j ACCEPT
Step 3: Allow outgoing connections to 192.168.0.1
# iptables -A OUTPUT -d 192.168.0.1 -j ACCEPTAdditional Options:
You can specify the destination port using the --dport option.
You can specify the protocol using the -p option.
You can specify the interface using the -i option for input, and the -o option for output.
For example below:
# iptables -A INPUT -s 192.168.0.1 -p tcp --dport 80 -i eth0 -j ACCEPT
This will allow connections from source 192.168.0.1 only on port 80, only on any IP address associated with eth0, only using TCP protocol.
# iptables -A OUTPUT -d 192.168.0.1 -p tcp --dport 443 -o eth0 -j ACCEPT
This will allow outgoing connections to destination IP 192.168.0.1 using protocol TCP, only on destination port 443, only from the interface eth0.