using ufw to block outgoing traffic to website

24,539

It will be:

sudo ufw deny out from any to _ipaddress_
Share:
24,539

Related videos on Youtube

JohnMerlino
Author by

JohnMerlino

Looking to master Trigonometry and Calculus and an interest in Ruby and JavaScript programming languages. I only use Linux (in particular Ubuntu Desktop) and Android. I like to write as well.

Updated on September 18, 2022

Comments

  • JohnMerlino
    JohnMerlino over 1 year

    I want to block traffic to a specific domain e.g. mysite.com. I tried blocking the ip address of the site but it does not work:

    ufw deny from 0.0.0.0 to ip_address_of_site
    

    I am still able to acess the website, even after a reboot.

    Any idea what I might be doing wrong?

  • user3021729
    user3021729 about 3 years
    Can you do it with a domain name? The best would be like this > sudo ufw deny out from any to *.domain.com
  • EdiD
    EdiD about 3 years
    @user3021729 AFAIK no. UFW creates iptables chains like ufw-user-output and ufw-user-input where you can put more complicated rules, but domain names probably won't work because iptables/nftables loads before dns and can't resolve names. Probably it will fail to load rules (but maybe something changed)
  • Sahin
    Sahin almost 3 years
    This didn't work for me with an Nginx website. After executing this, I can't ping that ip, but I can still reach to my website which is in that ip.
  • EdiD
    EdiD almost 3 years
    @Sahin can't tell anything without seeing configuration. Maybe you should ask a question describing your problem.
  • Admin
    Admin almost 2 years
    For me, it works fairly reliably. I just do dig domain to put whatever is in the A record, and it works well. (Not sure if that'll cause problems for cases where it's going through Cloudflare and such, though.)