28

I want to allow all LAN traffic to my Ubuntu server. I have read the documentation and see the command, but when I try to edit the command for my IP range I get an error. How can I allow all traffic starting at 192.168.15.0 - 192.168.15.255?

sudo ufw allow from 192.168.15.0/255 ERROR: Bad source address

It seems like the 15 (third octal) is causing the error. Almost like UFW does not expect a LAN to have a unique IP set.

Thank you

2
  • good question, but ufw is a simple interface above the iptables, you may able to do more control over packets via iptables. i prefer you to read this nice article about iptables: faqs.org/docs/iptables
    – pylover
    Jan 7, 2013 at 23:50
  • 1
    @pylover This is not helpful for this question. UFW is useful to simplifiy iptable tasks and what he wants to do is possible with it. Aug 5, 2014 at 18:43

2 Answers 2

51
sudo ufw allow from 192.168.15.0/24
4
  • 2
    Yes. 192.168.15.0/24 includes adresses from 192.168.15.1 to 192.168.15.254.
    – Roy
    Oct 13, 2009 at 16:41
  • 3
    For those wondering about the /24, see here. Essentially, the first 24 bits of the IP address (192.168.15) are fixed. Jun 10, 2019 at 9:55
  • 1
    I might be nitpicky, but 192.168.15.0/24 is actually from 192.168.15.0 to 192.168.15.255, totaling 256 IPs as 2^(32-24) Nov 25, 2020 at 15:41
  • For UDP, I had to create a separate rule: sudo ufw allow proto udp from 192.168.15.0/24 Jan 7 at 13:41
8

you need to do sudo ufw allow from yourip/24 like this

sudo ufw allow from 192.168.1.0/24 

replace 1 with your ip router.

To allow connections for particular IP addresses ranging from 192.168.1.1 to 192.168.1.254 to port 22 (SSH), run the following command

sudo ufw allow from 192.168.1.0/24 to any port 22
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .