Search This Blog

Linux: block outgoing traffic to specific ip or port using iptables or ufw

  • Using iptables:
    • # block outgoing traffic to ip 1.2.3.4
      iptables -A OUTPUT -d 1.2.3.4 -j DROP
      
      # block outgoing traffic to port 5678
      iptables -A OUTPUT -p tcp –dport 5678 -j DROP
      
      # block outgoing traffic to 1.2.3.4:5678
      iptables -A OUTPUT -p tcp -d 1.2.3.4 –dport 5678 -j DROP
      
  • Using ufw:
    • 
      # block outgoing traffic to ip 1.2.3.4
      ufw deny out to 1.2.3.4
       
      # block outgoing traffic to port 5678
      ufw deny out to any port 5678
      
      # block outgoing traffic to 1.2.3.4:5678
      ufw deny out to 1.2.3.4 port 5678
      

see also: Linux Iptables Block Outgoing Access To Selected or Specific IP Address / Port

3 comments:

  1. Windows XP/7 comes with firewall. You just need to figure out how to add rules using the Windows firewall.

    ReplyDelete
  2. Windows sucks. You can't do anything professional there. Forget it and move to Linux. Your welcome.

    ReplyDelete