How To: Whitelist An IP Address In IPTables
  • 09 Feb 2023
  • 1 Minute to read
  • Dark
    Light

How To: Whitelist An IP Address In IPTables

  • Dark
    Light

Article summary

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 ACCEPT

Additional 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.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence